react-native-oauth
react-native-oauth copied to clipboard
[Question] Android: My own providers are not supported yet?
I've implemented iOS app for my own oauth provider with rn-oauth. It works as I expected.
But on Android, it doesn't.
I got following error on OAuthManager#authorize().
04-09 22:22:55.143 5149 5189 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.github.scribejava.core.oauth.OAuth20Service.getAuthorizationUrl()' on a null object reference
So I read some code, found this static method, and it seems additional providers are not cosidered on Android.
static public OAuth20Service getApiFor20Provider(
final String providerName,
final HashMap params,
@Nullable final ReadableMap opts,
final String callbackUrl
) {
if (providerName.equalsIgnoreCase("facebook")) {
return OAuthManagerProviders.facebookService(params, opts, callbackUrl);
} else if (providerName.equalsIgnoreCase("google")) {
return OAuthManagerProviders.googleService(params, opts, callbackUrl);
} else if (providerName.equalsIgnoreCase("github")) {
return OAuthManagerProviders.githubService(params, opts, callbackUrl);
} else if (providerName.equalsIgnoreCase("slack")) {
return OAuthManagerProviders.slackService(params, opts, callbackUrl);
} else {
return null;
}
}
Not supported yet on Android ? Or there is the way to get my own provider work?
@pi-chan , could you take the time and check if it will work with this code of mine: https://github.com/fullstackreact/react-native-oauth/pull/111
It worked in my case but I would love to see it "just" works. You could do the check with npm install git+https://github.com/vbuch/react-native-oauth
Thank you in advance.
Thanks @vbuch , I've tried your code and got this build error.
cannot find symbol class ConfigurableApi
This class should be in scribejava library, but not. I found that there are no related files in scribejava repo.
Do you know anything?
Wow. Did i actually forget to commit this class? It does not need to be in scribejava. It needs to be in the package. I'll get it fixed today and letbyou know. Really my bad. Sorry!
@pi-chan The class is in there. It's in android/src/main/java/io/fullstack/oauth/services/ConfigurableApi.java and is defined as package com.github.scribejava.apis; if you're wondering how it appears from non-scribejava repo.
Thank you vbuch, your code almost works! I'll continue to try detailed test.
@pi-chan let me know if there are issues, and of course if it totally worked :-) Edit: Any news?
It has worked perfectly as I expected! thank you very much.
So it works and it's in npm now in 2.2.0
@vbuch,
{
mr: {
auth_version: '2.0',
authorize_url: 'https://o2.mail.ru/login',
access_token_url: 'https://o2.mail.ru/token',
revoke_token_url: 'https://o2.mail.ru/revoke',
scopes: 'userinfo',
callback_url: ({ app_name, client_id }) => {
return 'xxx-oauth-callback://';
}
}
}
Result
https://o2.mail.ru/login?response_type=code&client_id=xxx&redirect_uri=http%3A%2F%2Flocalhost%2Fmr&scope=userinfo&state=OAuthManagerProviders992041
redirect_uri=http%3A%2F%2Flocalhost%2Fmr
Expected
https://o2.mail.ru/login?response_type=code&client_id=xxx&redirect_uri=xxx-oauth-callback%3A%2F%2F&scope=userinfo&state=OAuthManagerProviders992041
redirect_uri=xxx-oauth-callback%3A%2F%2F
Why?

Oh! Sorry @monolithed but I haven't had any dealings with this package for more than 4 months. Can't help you out.
The problem is solved in accessTokenResponse of OAuthManagerModule.java:
String callbackUrl = (String) cfg.get("callback_url");
if (callbackUrl == null) {
callbackUrl = "http://localhost/" + providerName;
}