VictorAlbertos / RxSocialConnect-Android

OAuth RxJava extension for Android.
Apache License 2.0
257 stars 22 forks source link

Code extraction problem #17

Closed FuriousSeraphim closed 7 years ago

FuriousSeraphim commented 7 years ago

Hi, Victor. I found simple but painful problem with extracting code from uri in that case https://redirect_url#code=123456(VK OAuth2). Problem in #. Line String code = uri.getQueryParameter("code"); in rx_social_connect.internal.services.OAuth2Service returns null. I just copy-paste RxSocialConnect and add new method

public static <F extends Fragment> Observable<Response<F, com.github.scribejava.core.model.OAuth2AccessToken>> with(
            F fragment,
            OAuth20Service oAuth20Service,
            Service<OAuth2AccessToken, OAuth20Service> tokenService) {
        return startActivity(
                fragment,
                tokenService,
                oAuth20Service.getApi().getClass().getSimpleName(),
                OAuth2AccessToken.class)
                .map(new Func1<Response<Object, OAuth2AccessToken>, Response<F, com.github.scribejava.core.model.OAuth2AccessToken>>() {
                    @Override public Response<F, com.github.scribejava.core.model.OAuth2AccessToken> call(Response<Object, OAuth2AccessToken> response) {
                        return new Response(response.targetUI(), response.token());
                    }
                });
    }

that allow pass own rx_social_connect.internal.services.Service implementation to handle non-standart uri and correctly extract code. Can you add something like that in library core?

P.S. Sorry for my English :)

VictorAlbertos commented 7 years ago

Hi :)

I don't think that was the problem. Instead, it is related with #18

I added another example with Github provider and it works fine. Try the new version (0.1.4) and let me know.

Thanks for the feedback ;)

FuriousSeraphim commented 7 years ago

Hi, Victor I tried new version and problem is still here 1474136993928 1474137348370

VictorAlbertos commented 7 years ago

What provider is that? Is it a custom one? I said so because I checked the available providers on Scribe and vk is not listed.

And it seems that the query string provided does not honor the standard.

FuriousSeraphim commented 7 years ago

vk is Vkontakte

And it seems that the query string provided does not honor the standard.

It's the only reason why i created this issue (and created own temporary workaround) :)

VictorAlbertos commented 7 years ago

Try the new version 0.1.5 and let me know :)

And provide a custom query string parsing strategy:

QueryString.PARSER.replaceStrategyOAuth2(new QueryStringStrategy() {
      @Override public String extractCode(Uri uri) {
        //whatever you need to do.
      }

      @Nullable @Override public String extractError(Uri uri) {
        return uri.getQueryParameter("error");
      }
    });