openid / AppAuth-Android

Android client SDK for communicating with OAuth 2.0 and OpenID Connect providers.
https://openid.github.io/AppAuth-Android
Apache License 2.0
2.84k stars 883 forks source link

Chrome custom tab redirection problem #353

Open JavierSegoviaCordoba opened 6 years ago

JavierSegoviaCordoba commented 6 years ago

I am having a problems to redirect to my app.

I want to oauth2 with GitLab API. I tried a lot of combinations with the manifest and the API, nothing works.

I tried http and https. I tried to use normal url (http://...) or use the inverse url (com.myapp...)

The chrome custom tab never close for itself, I have to force to close it, then it redirects to my new activity but the response is null (I accepted and I got redirected in the chrome custom tab to the gitlab callball url).

Why Chrome custom tabs doesnt't close for itself? Why response is null?

iainmcgin commented 6 years ago

Please confirm that:

  1. The redirect URL you are using is correctly captured by your app. You can test this from adb:
adb shell am start -W -a android.intent.action.VIEW \
  -c android.intent.category.DEFAULT  \
  -d YOUR_REDIRECT_URL

If the redirect URI is being correctly handled by your app, it should open or an app picker should appear listing your app as an option. If nothing happens, your app is not registered to handle that redirect URI.

  1. The redirect occurs after some user action is taken, like tapping a button or link. If the redirect happens automatically, Chrome may not forward the request to your app, for security reasons. Search for other issues with label "redirect-handling" for further discussion of this.

If you need more help, please provide the data filters defined for RedirectUriReceiverActivity for your app, and the redirect URI you see in the browser that fails to transfer to your app (you can exclude any query / fragment, to avoid sharing any auth codes or tokens).

EarlyWild commented 6 years ago

Can you please provide more detail on this issue? I am having the same issue. I have ran the test above and can verify that my redirect URL is being captured by my app. As for point 2, the redirect happens once the user logs in, so would you consider that to be automatic? If so are there any known solutions to get chrome to forward the request? My redirect URI is http://127.0.0.1:64000 if that makes a difference.

I have looked through the issues labeled redirect-handling and did not see anything useful. (I probably have missed something)

mtangoo commented 6 years ago

Two suggestions I can give (Assuming your server is in local machine and they share network connection like same wireless router or phone tethering)

This will get you solved in case the issue is not mis-configuration of stuffs in you app/manifest

EarlyWild commented 6 years ago

Okay, thank you for the information. I am still having no luck resolving this issue. If my callback is http://127.0.0.1:64000, what should my intent look like? This is what I currently have:

Gradle: manifestPlaceholders = [ 'appAuthRedirectScheme': 'http://127.0.0.1' ]

Manifest: ` <activity android:name="net.openid.appauth.RedirectUriReceiverActivity" tools:node="replace">

    </activity>`
mtangoo commented 6 years ago

How will your mobile app then access 127.0.0.1 (localhost)? If its the android emulator then that's not the address and if it a physical device then it does not have access to localhost.

TL:DR - localhost won't work.

EarlyWild commented 6 years ago

I managed to get it to work using the demo app (I do not know why it works), but now I am getting a code exchange error "AuthorizationException: {"type":0,"code":3,"errorDescription":"Network error"}" when trying to perform a token request.

I am using a static client secret (I know... it is unsafe but I have no choice), and I have modified the code to do so following the guide, but I get a network error none the less (with and without the client secret).

karunanaik commented 5 years ago

@EarlyWild Were you ever able to get this issue resolved about "Network Error"? I am facing the same issue. If you were able to solve this issue then can you please let me know what was the solution?

bizzbyster commented 5 years ago

@karunanaik @EarlyWild did you ever get this figured out?

karunanaik commented 5 years ago

@bizzbyster I ended up using another library. https://github.com/wuman/android-oauth-client/

mtangoo commented 5 years ago

@karunanaik

The android-oauth-client library helps you to easily add an OAuth flow to your existing Android application. It automatically shows a customizable Android dialog with WebView to guide the user to eventually grant you an access token.

that's dangerous!

EarlyWild commented 4 years ago

@bizzbyster I realize its a little late but... My solution was to blacklist Custom Chrome Tabs as follows

builder = AppAuthConfiguration.Builder().setBrowserMatcher( BrowserBlacklist(VersionedBrowserMatcher.CHROME_CUSTOM_TAB))

This results in either a non-chrome browser or the full chrome browser to be used for authentication. For some strange reason, 127.0.0.1 redirect is blocked by chrome tabs but not by chrome itself.