@@ -72,6 +72,8 @@ public class AuthActivity extends Activity {
7272
7373 public static final String EXTRA_EXPIRES_AT = "EXPIRES_AT" ;
7474
75+ public static final String EXTRA_SCOPE = "SCOPE" ;
76+
7577 /**
7678 * Used for internal authentication. You won't ever have to use this.
7779 */
@@ -181,6 +183,7 @@ public SecureRandom getSecureRandom() {
181183 private static TokenAccessType sTokenAccessType ;
182184 private static DbxRequestConfig sRequestConfig ;
183185 private static DbxHost sHost ;
186+ private static String sScope ;
184187
185188 // These instance variables need not be stored in savedInstanceState as onNewIntent()
186189 // does not read them.
@@ -192,7 +195,8 @@ public SecureRandom getSecureRandom() {
192195 private TokenAccessType mTokenAccessType ;
193196 private DbxPKCEManager mPKCEManager ;
194197 private DbxRequestConfig mRequestConfig ;
195- private static DbxHost mHost ;
198+ private DbxHost mHost ;
199+ private String mScope ;
196200
197201 // Stored in savedInstanceState to track an ongoing auth attempt, which
198202 // must include a locally-generated nonce in the response.
@@ -215,7 +219,8 @@ static void setAuthParams(String appKey, String desiredUid,
215219 */
216220 static void setAuthParams (String appKey , String desiredUid ,
217221 String [] alreadyAuthedUids , String webHost , String apiType ) {
218- setAuthParams (appKey , desiredUid , alreadyAuthedUids , null , null , null , null , null , null );
222+ setAuthParams (appKey , desiredUid , alreadyAuthedUids , null , null , null , null , null , null ,
223+ null );
219224 }
220225
221226 /**
@@ -224,7 +229,7 @@ static void setAuthParams(String appKey, String desiredUid,
224229 static void setAuthParams (String appKey , String desiredUid ,
225230 String [] alreadyAuthedUids , String sessionId ) {
226231 setAuthParams (appKey , desiredUid , alreadyAuthedUids , sessionId , null , null , null , null ,
227- null );
232+ null , null );
228233 }
229234
230235 /**
@@ -234,7 +239,7 @@ static void setAuthParams(String appKey, String desiredUid,
234239 static void setAuthParams (String appKey , String desiredUid ,
235240 String [] alreadyAuthedUids , String sessionId , String webHost ,
236241 String apiType , TokenAccessType tokenAccessType ,
237- DbxRequestConfig requestConfig , DbxHost host ) {
242+ DbxRequestConfig requestConfig , DbxHost host , String scope ) {
238243 sAppKey = appKey ;
239244 sDesiredUid = desiredUid ;
240245 sAlreadyAuthedUids = (alreadyAuthedUids != null ) ? alreadyAuthedUids : new String [0 ];
@@ -252,6 +257,7 @@ static void setAuthParams(String appKey, String desiredUid,
252257 } else {
253258 sHost = DbxHost .DEFAULT ;
254259 }
260+ sScope = scope ;
255261 }
256262
257263 /**
@@ -267,7 +273,8 @@ static void setAuthParams(String appKey, String desiredUid,
267273 */
268274 public static Intent makeIntent (Context context , String appKey , String webHost ,
269275 String apiType ) {
270- return makeIntent (context , appKey , null , null , null , webHost , apiType , null , null , null );
276+ return makeIntent (context , appKey , null , null , null , webHost , apiType , null , null , null ,
277+ null );
271278 }
272279
273280 /**
@@ -296,7 +303,7 @@ public static Intent makeIntent(Context context, String appKey, String desiredUi
296303 throw new IllegalArgumentException ("'appKey' can't be null" );
297304 }
298305 setAuthParams (appKey , desiredUid , alreadyAuthedUids , sessionId , webHost , apiType , null ,
299- null , null );
306+ null , null , null );
300307 return new Intent (context , AuthActivity .class );
301308 }
302309
@@ -306,12 +313,12 @@ public static Intent makeIntent(Context context, String appKey, String desiredUi
306313 static Intent makeIntent (
307314 Context context , String appKey , String desiredUid , String [] alreadyAuthedUids ,
308315 String sessionId , String webHost , String apiType , TokenAccessType tokenAccessType ,
309- DbxRequestConfig requestConfig , DbxHost host
316+ DbxRequestConfig requestConfig , DbxHost host , String scope
310317 ) {
311318 if (appKey == null ) throw new IllegalArgumentException ("'appKey' can't be null" );
312319 setAuthParams (
313320 appKey , desiredUid , alreadyAuthedUids , sessionId , webHost , apiType , tokenAccessType ,
314- requestConfig , host
321+ requestConfig , host , scope
315322 );
316323 return new Intent (context , AuthActivity .class );
317324 }
@@ -429,6 +436,7 @@ protected void onCreate(Bundle savedInstanceState) {
429436 mTokenAccessType = sTokenAccessType ;
430437 mRequestConfig = sRequestConfig ;
431438 mHost = sHost ;
439+ mScope = sScope ;
432440
433441 if (savedInstanceState == null ) {
434442 result = null ;
@@ -626,6 +634,7 @@ protected void onNewIntent(Intent intent) {
626634 newResult .putExtra (EXTRA_EXPIRES_AT , dbxAuthFinish .getExpiresAt ());
627635 newResult .putExtra (EXTRA_UID , dbxAuthFinish .getUserId ());
628636 newResult .putExtra (EXTRA_CONSUMER_KEY , mAppKey );
637+ newResult .putExtra (EXTRA_SCOPE , dbxAuthFinish .getScope ());
629638 }
630639 } catch (Exception e ) {
631640 newResult = null ;
@@ -637,7 +646,6 @@ protected void onNewIntent(Intent intent) {
637646 // Unsuccessful auth, or missing required parameters.
638647 newResult = null ;
639648 }
640-
641649 authFinished (newResult );
642650 }
643651
@@ -692,13 +700,19 @@ private String createPKCEStateNonce() {
692700 }
693701
694702 private String createExtraQueryParams () {
695- return String .format (
703+ String param = String .format (Locale . US ,
696704 "%s=%s&%s=%s&%s=%s&%s=%s" ,
697705 "code_challenge" , mPKCEManager .getCodeChallenge (),
698706 "code_challenge_method" , DbxPKCEManager .CODE_CHALLENGE_METHODS ,
699707 "token_access_type" , mTokenAccessType .toString (),
700708 "response_type" , "code"
701709 );
710+
711+ if (mScope != null ) {
712+ param += String .format (Locale .US , "%s=%s" , "scope" , mScope );
713+ }
714+
715+ return param ;
702716 }
703717
704718 private enum TokenType {
0 commit comments