AppAuth-Android
AppAuth-Android copied to clipboard
Chrome custom tab redirection problem
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?
Please confirm that:
- 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.
- 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).
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)
Two suggestions I can give (Assuming your server is in local machine and they share network connection like same wireless router or phone tethering)
- start your localhost with address 0.0.0.0:64000 instead of 127.0.0.0:640000
- Use your computer (acting as server) external IP, something like 192.168.x.x (If you use windows ipconfig will help and *nix you can try
ifconfig |grep inet
and get it)
This will get you solved in case the issue is not mis-configuration of stuffs in you app/manifest
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"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="http" android:host="127.0.0.1" android:port="64000"/> </intent-filter> </activity>
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.
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).
@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?
@karunanaik @EarlyWild did you ever get this figured out?
@bizzbyster I ended up using another library. https://github.com/wuman/android-oauth-client/
@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!
@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.