11package com .dropbox .core .android ;
22
33import java .security .SecureRandom ;
4+ import java .util .ArrayList ;
5+ import java .util .Arrays ;
46import java .util .List ;
57import java .util .Locale ;
68
@@ -666,15 +668,20 @@ private void startWebAuth(String state) {
666668 // Note that the API treats alreadyAuthUid of 0 and not present equivalently.
667669 String alreadyAuthedUid = (mAlreadyAuthedUids .length > 0 ) ? mAlreadyAuthedUids [0 ] : "0" ;
668670
669- String [] params = {
670- "k" , mAppKey ,
671- "n" , alreadyAuthedUid ,
672- "api" , mApiType ,
673- "state" , state ,
674- "extra_query_params" , createExtraQueryParams ()
675- };
671+ List <String > params = new ArrayList <String >(Arrays .asList (
672+ "k" , mAppKey ,
673+ "n" , alreadyAuthedUid ,
674+ "api" , mApiType ,
675+ "state" , state
676+ ));
676677
677- String url = DbxRequestUtil .buildUrlWithParams (locale .toString (), mHost .getWeb (), path , params );
678+ if (mTokenAccessType != null ) {
679+ params .add ("extra_query_params" );
680+ params .add (createExtraQueryParams ());
681+ }
682+
683+ String url = DbxRequestUtil .buildUrlWithParams (locale .toString (), mHost .getWeb (), path ,
684+ params .toArray (new String [0 ]));
678685
679686 Intent intent = new Intent (Intent .ACTION_VIEW , Uri .parse (url ));
680687 startActivity (intent );
@@ -700,6 +707,11 @@ private String createPKCEStateNonce() {
700707 }
701708
702709 private String createExtraQueryParams () {
710+ if (mTokenAccessType == null ) {
711+ throw new IllegalStateException ("Extra Query Param should only be used in short live " +
712+ "token flow." );
713+ }
714+
703715 String param = String .format (Locale .US ,
704716 "%s=%s&%s=%s&%s=%s&%s=%s" ,
705717 "code_challenge" , mPKCEManager .getCodeChallenge (),
@@ -709,7 +721,7 @@ private String createExtraQueryParams() {
709721 );
710722
711723 if (mScope != null ) {
712- param += String .format (Locale .US , "%s=%s" , "scope" , mScope );
724+ param += String .format (Locale .US , "& %s=%s" , "scope" , mScope );
713725 }
714726
715727 return param ;
0 commit comments