28
28
import com .github .scribejava .apis .GoogleApi20 ;
29
29
import com .github .scribejava .apis .GitHubApi ;
30
30
31
+ import com .github .scribejava .apis .ConfigurableApi ;
31
32
import com .github .scribejava .apis .SlackApi ;
32
33
33
34
import com .facebook .react .bridge .ReadableMap ;
@@ -59,15 +60,25 @@ static public OAuth20Service getApiFor20Provider(
59
60
) {
60
61
if (providerName .equalsIgnoreCase ("facebook" )) {
61
62
return OAuthManagerProviders .facebookService (params , opts , callbackUrl );
62
- } else if (providerName .equalsIgnoreCase ("google" )) {
63
+ }
64
+
65
+ if (providerName .equalsIgnoreCase ("google" )) {
63
66
return OAuthManagerProviders .googleService (params , opts , callbackUrl );
64
- } else if (providerName .equalsIgnoreCase ("github" )) {
67
+ }
68
+
69
+ if (providerName .equalsIgnoreCase ("github" )) {
65
70
return OAuthManagerProviders .githubService (params , opts , callbackUrl );
66
- } else if (providerName .equalsIgnoreCase ("slack" )) {
71
+ }
72
+
73
+ if (providerName .equalsIgnoreCase ("slack" )) {
67
74
return OAuthManagerProviders .slackService (params , opts , callbackUrl );
68
- } else {
69
- return null ;
70
75
}
76
+
77
+ if (params .containsKey ("access_token_url" ) && params .containsKey ("authorize_url" )) {
78
+ return OAuthManagerProviders .configurableService (params , opts , callbackUrl );
79
+ }
80
+
81
+ return null ;
71
82
}
72
83
73
84
static public OAuthRequest getRequestForProvider (
@@ -78,9 +89,9 @@ static public OAuthRequest getRequestForProvider(
78
89
final HashMap <String ,Object > cfg ,
79
90
@ Nullable final ReadableMap params
80
91
) {
81
- final OAuth10aService service =
92
+ final OAuth10aService service =
82
93
OAuthManagerProviders .getApiFor10aProvider (providerName , cfg , null , null );
83
-
94
+
84
95
String token = oa1token .getToken ();
85
96
OAuthConfig config = service .getConfig ();
86
97
OAuthRequest request = new OAuthRequest (httpVerb , url .toString (), config );
@@ -100,14 +111,14 @@ static public OAuthRequest getRequestForProvider(
100
111
) {
101
112
final OAuth20Service service =
102
113
OAuthManagerProviders .getApiFor20Provider (providerName , cfg , null , null );
103
-
114
+
104
115
OAuthConfig config = service .getConfig ();
105
116
OAuthRequest request = new OAuthRequest (httpVerb , url .toString (), config );
106
117
String token = oa2token .getAccessToken ();
107
118
108
119
request = OAuthManagerProviders .addParametersToRequest (request , token , params );
109
120
110
- //
121
+ //
111
122
Log .d (TAG , "Making request for " + providerName + " to add token " + token );
112
123
// Need a way to standardize this, but for now
113
124
if (providerName .equalsIgnoreCase ("slack" )) {
@@ -146,12 +157,12 @@ static private OAuthRequest addParametersToRequest(
146
157
}
147
158
148
159
private static OAuth10aService twitterService (
149
- final HashMap cfg ,
160
+ final HashMap cfg ,
150
161
@ Nullable final ReadableMap opts ,
151
162
final String callbackUrl ) {
152
163
String consumerKey = (String ) cfg .get ("consumer_key" );
153
164
String consumerSecret = (String ) cfg .get ("consumer_secret" );
154
-
165
+
155
166
ServiceBuilder builder = new ServiceBuilder ()
156
167
.apiKey (consumerKey )
157
168
.apiSecret (consumerSecret )
@@ -167,20 +178,20 @@ private static OAuth10aService twitterService(
167
178
if (callbackUrl != null ) {
168
179
builder .callback (callbackUrl );
169
180
}
170
-
181
+
171
182
return builder .build (TwitterApi .instance ());
172
183
}
173
184
174
185
private static OAuth20Service facebookService (
175
- final HashMap cfg ,
186
+ final HashMap cfg ,
176
187
@ Nullable final ReadableMap opts ,
177
188
final String callbackUrl ) {
178
189
ServiceBuilder builder = OAuthManagerProviders ._oauth2ServiceBuilder (cfg , opts , callbackUrl );
179
190
return builder .build (FacebookApi .instance ());
180
191
}
181
192
182
193
private static OAuth20Service googleService (
183
- final HashMap cfg ,
194
+ final HashMap cfg ,
184
195
@ Nullable final ReadableMap opts ,
185
196
final String callbackUrl )
186
197
{
@@ -189,7 +200,7 @@ private static OAuth20Service googleService(
189
200
}
190
201
191
202
private static OAuth20Service githubService (
192
- final HashMap cfg ,
203
+ final HashMap cfg ,
193
204
@ Nullable final ReadableMap opts ,
194
205
final String callbackUrl )
195
206
{
@@ -198,8 +209,28 @@ private static OAuth20Service githubService(
198
209
return builder .build (GitHubApi .instance ());
199
210
}
200
211
212
+ private static OAuth20Service configurableService (
213
+ final HashMap cfg ,
214
+ @ Nullable final ReadableMap opts ,
215
+ final String callbackUrl
216
+ ) {
217
+ ServiceBuilder builder = OAuthManagerProviders ._oauth2ServiceBuilder (cfg , opts , callbackUrl );
218
+ Log .d (TAG , "Creating ConfigurableApi" );
219
+ //Log.d(TAG, " authorize_url: " + cfg.get("authorize_url"));
220
+ //Log.d(TAG, " access_token_url: " + cfg.get("access_token_url"));
221
+ ConfigurableApi api = ConfigurableApi .instance ()
222
+ .setAccessTokenEndpoint ((String ) cfg .get ("access_token_url" ))
223
+ .setAuthorizationBaseUrl ((String ) cfg .get ("authorize_url" ));
224
+ if (cfg .containsKey ("access_token_verb" )) {
225
+ //Log.d(TAG, " access_token_verb: " + cfg.get("access_token_verb"));
226
+ api .setAccessTokenVerb ((String ) cfg .get ("access_token_verb" ));
227
+ }
228
+
229
+ return builder .build (api );
230
+ }
231
+
201
232
private static OAuth20Service slackService (
202
- final HashMap cfg ,
233
+ final HashMap cfg ,
203
234
@ Nullable final ReadableMap opts ,
204
235
final String callbackUrl
205
236
) {
@@ -236,13 +267,13 @@ private static ServiceBuilder _oauth2ServiceBuilder(
236
267
String scopeStr = OAuthManagerProviders .getScopeString (scopes , "," );
237
268
builder .scope (scopeStr );
238
269
}
239
-
270
+
240
271
if (opts != null && opts .hasKey ("scopes" )) {
241
272
scopes = (String ) opts .getString ("scopes" );
242
273
String scopeStr = OAuthManagerProviders .getScopeString (scopes , "," );
243
274
builder .scope (scopeStr );
244
275
}
245
-
276
+
246
277
if (callbackUrl != null ) {
247
278
builder .callback (callbackUrl );
248
279
}
@@ -261,4 +292,4 @@ private static String getScopeString(
261
292
Log .d (TAG , "array: " + array + " (" + array .size () + ") from " + scopes );
262
293
return TextUtils .join (joinBy , array );
263
294
}
264
- }
295
+ }
0 commit comments