Skip to content

Commit f9ee811

Browse files
committed
Add ConfigurableApi to support custom providers.
1 parent a521863 commit f9ee811

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

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

+29-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.github.scribejava.apis.GoogleApi20;
2929
import com.github.scribejava.apis.GitHubApi;
3030

31+
import com.github.scribejava.apis.ConfigurableApi;
3132
import com.github.scribejava.apis.SlackApi;
3233

3334
import com.facebook.react.bridge.ReadableMap;
@@ -59,15 +60,27 @@ 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);
6875
} else {
6976
return null;
7077
}
78+
79+
if (params.containsKey("access_token_url") && params.containsKey("authorize_url")) {
80+
return OAuthManagerProviders.configurableService(params, opts, callbackUrl);
81+
}
82+
83+
return null;
7184
}
7285

7386
static public OAuthRequest getRequestForProvider(
@@ -198,6 +211,19 @@ private static OAuth20Service githubService(
198211
return builder.build(GitHubApi.instance());
199212
}
200213

214+
private static OAuth20Service configurableService(
215+
final HashMap cfg,
216+
@Nullable final ReadableMap opts,
217+
final String callbackUrl
218+
) {
219+
ServiceBuilder builder = OAuthManagerProviders._oauth2ServiceBuilder(cfg, opts, callbackUrl);
220+
ConfigurableApi api = ConfigurableApi.instance()
221+
.setAccessTokenEndpoint((String) cfg.get("access_token_url"))
222+
.setAuthorizationBaseUrl((String) cfg.get("authorize_url"));
223+
224+
return builder.build(api);
225+
}
226+
201227
private static OAuth20Service slackService(
202228
final HashMap cfg,
203229
@Nullable final ReadableMap opts,

0 commit comments

Comments
 (0)