Skip to content

Commit dd71d30

Browse files
committed
Fixed oauth scope string to be dynamic
1 parent f460b9d commit dd71d30

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

android/src/main/java/io/fullstack/oauth/OAuthManagerProviders.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import android.util.Log;
44
import java.util.HashMap;
55
import java.util.Random;
6+
import java.util.List;
67
import android.support.annotation.Nullable;
78
import java.net.URL;
89
import java.net.MalformedURLException;
10+
import android.text.TextUtils;
11+
import java.util.Arrays;
912

1013
import com.github.scribejava.core.model.Verb;
1114
import com.github.scribejava.core.builder.api.BaseApi;
@@ -156,7 +159,9 @@ private static OAuth10aService twitterService(
156159

157160
String scopes = (String) cfg.get("scopes");
158161
if (scopes != null) {
159-
builder.scope(scopes);
162+
// String scopeStr = OAuthManagerProviders.getScopeString(scopes, "+");
163+
// Log.d(TAG, "scopeStr: " + scopeStr);
164+
// builder.scope(scopeStr);
160165
}
161166

162167
if (callbackUrl != null) {
@@ -228,10 +233,14 @@ private static ServiceBuilder _oauth2ServiceBuilder(
228233
String scopes = "";
229234
if (cfg.containsKey("scopes")) {
230235
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")) {
233241
scopes = (String) opts.getString("scopes");
234-
builder.scope(scopes);
242+
String scopeStr = OAuthManagerProviders.getScopeString(scopes, ",");
243+
builder.scope(scopeStr);
235244
}
236245

237246
if (callbackUrl != null) {
@@ -240,4 +249,16 @@ private static ServiceBuilder _oauth2ServiceBuilder(
240249

241250
return builder;
242251
}
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+
}
243264
}

0 commit comments

Comments
 (0)