3
3
import android .util .Log ;
4
4
import java .util .HashMap ;
5
5
import java .util .Random ;
6
+ import java .util .List ;
6
7
import android .support .annotation .Nullable ;
7
8
import java .net .URL ;
8
9
import java .net .MalformedURLException ;
10
+ import android .text .TextUtils ;
11
+ import java .util .Arrays ;
9
12
10
13
import com .github .scribejava .core .model .Verb ;
11
14
import com .github .scribejava .core .builder .api .BaseApi ;
@@ -156,7 +159,9 @@ private static OAuth10aService twitterService(
156
159
157
160
String scopes = (String ) cfg .get ("scopes" );
158
161
if (scopes != null ) {
159
- builder .scope (scopes );
162
+ // String scopeStr = OAuthManagerProviders.getScopeString(scopes, "+");
163
+ // Log.d(TAG, "scopeStr: " + scopeStr);
164
+ // builder.scope(scopeStr);
160
165
}
161
166
162
167
if (callbackUrl != null ) {
@@ -228,10 +233,14 @@ private static ServiceBuilder _oauth2ServiceBuilder(
228
233
String scopes = "" ;
229
234
if (cfg .containsKey ("scopes" )) {
230
235
scopes = (String ) cfg .get ("scopes" );
231
- builder .scope (scopes );
232
- } else if (opts != null && opts .hasKey ("scopes" )) {
236
+ String scopeStr = OAuthManagerProviders .getScopeString (scopes , "," );
237
+ builder .scope (scopeStr );
238
+ }
239
+
240
+ if (opts != null && opts .hasKey ("scopes" )) {
233
241
scopes = (String ) opts .getString ("scopes" );
234
- builder .scope (scopes );
242
+ String scopeStr = OAuthManagerProviders .getScopeString (scopes , "," );
243
+ builder .scope (scopeStr );
235
244
}
236
245
237
246
if (callbackUrl != null ) {
@@ -240,4 +249,16 @@ private static ServiceBuilder _oauth2ServiceBuilder(
240
249
241
250
return builder ;
242
251
}
252
+
253
+ /**
254
+ * Convert a list of scopes by space or string into an array
255
+ */
256
+ private static String getScopeString (
257
+ final String scopes ,
258
+ final String joinBy
259
+ ) {
260
+ List <String > array = Arrays .asList (scopes .replaceAll ("\\ s" , "" ).split ("[ ,]+" ));
261
+ Log .d (TAG , "array: " + array + " (" + array .size () + ") from " + scopes );
262
+ return TextUtils .join (joinBy , array );
263
+ }
243
264
}
0 commit comments