react-native-oauth icon indicating copy to clipboard operation
react-native-oauth copied to clipboard

[Question] Android: My own providers are not supported yet?

Open pi-chan opened this issue 8 years ago • 11 comments
trafficstars

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 avatar Apr 09 '17 23:04 pi-chan

@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.

vbuch avatar May 29 '17 13:05 vbuch

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?

pi-chan avatar May 30 '17 02:05 pi-chan

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!

vbuch avatar May 30 '17 05:05 vbuch

@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.

vbuch avatar May 30 '17 07:05 vbuch

Thank you vbuch, your code almost works! I'll continue to try detailed test.

pi-chan avatar May 30 '17 09:05 pi-chan

@pi-chan let me know if there are issues, and of course if it totally worked :-) Edit: Any news?

vbuch avatar Jun 05 '17 06:06 vbuch

It has worked perfectly as I expected! thank you very much.

pi-chan avatar Jun 05 '17 06:06 pi-chan

So it works and it's in npm now in 2.2.0

vbuch avatar Aug 07 '17 21:08 vbuch

@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? img-2018-01-24-19-39-39

monolithed avatar Jan 24 '18 16:01 monolithed

Oh! Sorry @monolithed but I haven't had any dealings with this package for more than 4 months. Can't help you out.

vbuch avatar Jan 24 '18 17:01 vbuch

The problem is solved in accessTokenResponse of OAuthManagerModule.java:

      String callbackUrl = (String) cfg.get("callback_url");

      if (callbackUrl == null) {
        callbackUrl = "http://localhost/" + providerName;
      }

monolithed avatar Jan 28 '18 22:01 monolithed