2828import com .github .scribejava .apis .GoogleApi20 ;
2929import com .github .scribejava .apis .GitHubApi ;
3030
31+ import com .github .scribejava .apis .ConfigurableApi ;
3132import com .github .scribejava .apis .SlackApi ;
3233
3334import com .facebook .react .bridge .ReadableMap ;
@@ -59,15 +60,25 @@ static public OAuth20Service getApiFor20Provider(
5960 ) {
6061 if (providerName .equalsIgnoreCase ("facebook" )) {
6162 return OAuthManagerProviders .facebookService (params , opts , callbackUrl );
62- } else if (providerName .equalsIgnoreCase ("google" )) {
63+ }
64+
65+ if (providerName .equalsIgnoreCase ("google" )) {
6366 return OAuthManagerProviders .googleService (params , opts , callbackUrl );
64- } else if (providerName .equalsIgnoreCase ("github" )) {
67+ }
68+
69+ if (providerName .equalsIgnoreCase ("github" )) {
6570 return OAuthManagerProviders .githubService (params , opts , callbackUrl );
66- } else if (providerName .equalsIgnoreCase ("slack" )) {
71+ }
72+
73+ if (providerName .equalsIgnoreCase ("slack" )) {
6774 return OAuthManagerProviders .slackService (params , opts , callbackUrl );
68- } else {
69- return null ;
7075 }
76+
77+ if (params .containsKey ("access_token_url" ) && params .containsKey ("authorize_url" )) {
78+ return OAuthManagerProviders .configurableService (params , opts , callbackUrl );
79+ }
80+
81+ return null ;
7182 }
7283
7384 static public OAuthRequest getRequestForProvider (
@@ -78,9 +89,9 @@ static public OAuthRequest getRequestForProvider(
7889 final HashMap <String ,Object > cfg ,
7990 @ Nullable final ReadableMap params
8091 ) {
81- final OAuth10aService service =
92+ final OAuth10aService service =
8293 OAuthManagerProviders .getApiFor10aProvider (providerName , cfg , null , null );
83-
94+
8495 String token = oa1token .getToken ();
8596 OAuthConfig config = service .getConfig ();
8697 OAuthRequest request = new OAuthRequest (httpVerb , url .toString (), config );
@@ -100,14 +111,14 @@ static public OAuthRequest getRequestForProvider(
100111 ) {
101112 final OAuth20Service service =
102113 OAuthManagerProviders .getApiFor20Provider (providerName , cfg , null , null );
103-
114+
104115 OAuthConfig config = service .getConfig ();
105116 OAuthRequest request = new OAuthRequest (httpVerb , url .toString (), config );
106117 String token = oa2token .getAccessToken ();
107118
108119 request = OAuthManagerProviders .addParametersToRequest (request , token , params );
109120
110- //
121+ //
111122 Log .d (TAG , "Making request for " + providerName + " to add token " + token );
112123 // Need a way to standardize this, but for now
113124 if (providerName .equalsIgnoreCase ("slack" )) {
@@ -146,12 +157,12 @@ static private OAuthRequest addParametersToRequest(
146157 }
147158
148159 private static OAuth10aService twitterService (
149- final HashMap cfg ,
160+ final HashMap cfg ,
150161 @ Nullable final ReadableMap opts ,
151162 final String callbackUrl ) {
152163 String consumerKey = (String ) cfg .get ("consumer_key" );
153164 String consumerSecret = (String ) cfg .get ("consumer_secret" );
154-
165+
155166 ServiceBuilder builder = new ServiceBuilder ()
156167 .apiKey (consumerKey )
157168 .apiSecret (consumerSecret )
@@ -167,20 +178,20 @@ private static OAuth10aService twitterService(
167178 if (callbackUrl != null ) {
168179 builder .callback (callbackUrl );
169180 }
170-
181+
171182 return builder .build (TwitterApi .instance ());
172183 }
173184
174185 private static OAuth20Service facebookService (
175- final HashMap cfg ,
186+ final HashMap cfg ,
176187 @ Nullable final ReadableMap opts ,
177188 final String callbackUrl ) {
178189 ServiceBuilder builder = OAuthManagerProviders ._oauth2ServiceBuilder (cfg , opts , callbackUrl );
179190 return builder .build (FacebookApi .instance ());
180191 }
181192
182193 private static OAuth20Service googleService (
183- final HashMap cfg ,
194+ final HashMap cfg ,
184195 @ Nullable final ReadableMap opts ,
185196 final String callbackUrl )
186197 {
@@ -189,7 +200,7 @@ private static OAuth20Service googleService(
189200 }
190201
191202 private static OAuth20Service githubService (
192- final HashMap cfg ,
203+ final HashMap cfg ,
193204 @ Nullable final ReadableMap opts ,
194205 final String callbackUrl )
195206 {
@@ -198,8 +209,28 @@ private static OAuth20Service githubService(
198209 return builder .build (GitHubApi .instance ());
199210 }
200211
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+
201232 private static OAuth20Service slackService (
202- final HashMap cfg ,
233+ final HashMap cfg ,
203234 @ Nullable final ReadableMap opts ,
204235 final String callbackUrl
205236 ) {
@@ -236,13 +267,13 @@ private static ServiceBuilder _oauth2ServiceBuilder(
236267 String scopeStr = OAuthManagerProviders .getScopeString (scopes , "," );
237268 builder .scope (scopeStr );
238269 }
239-
270+
240271 if (opts != null && opts .hasKey ("scopes" )) {
241272 scopes = (String ) opts .getString ("scopes" );
242273 String scopeStr = OAuthManagerProviders .getScopeString (scopes , "," );
243274 builder .scope (scopeStr );
244275 }
245-
276+
246277 if (callbackUrl != null ) {
247278 builder .callback (callbackUrl );
248279 }
@@ -261,4 +292,4 @@ private static String getScopeString(
261292 Log .d (TAG , "array: " + array + " (" + array .size () + ") from " + scopes );
262293 return TextUtils .join (joinBy , array );
263294 }
264- }
295+ }
0 commit comments