I have been trying to get google OAuth to work on android and I am continuously hitting roadblocks.
Right now, in my manifest, I've added the custom url scheme and host for my redirect URL, like so:
When I try to use that URL scheme in the Google OAuth intent, I get the following error:
After some googling, I found this answer on stackoverflow, telling me to reformat my URL scheme to com.myapp.myscheme:/oauth
, so I set the redirect_uri to com.loop.loop:/oauth
, since com.loop
is my package name, loop
is my scheme, and oauth
is my host.
After trying that, I get this error:
This error tells me that I need to register my redirect URI somewhere, so I go to the Google API console where I registered my client_id. However, there is literally no place to register my redirect URI:
For some reason, using com.loop:/oauth
works, but it doesn't redirect back to my app after authorizing. Instead, it just goes to the Google homepage.
Here is the code I'm using to run the chrome custom tabs:
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent chromeIntent = builder.build();
chromeIntent.launchUrl(this, Uri.parse(url));
This is the OAuth URL I'm using:
https://accounts.google.com/o/oauth2/auth
I have no idea what I'm supposed to do here, and the documentation is not very helpful. I'm also aware there is an Android Google Auth library, but I'm not interested in that because that is specific to Google, and I'm just trying to make a generic OAuth controller. I have also tried using a WebView, but Google doesn't allow OAuth through a WebView. Please help
Well I was able to figure it out from this.
Apparently for google oauth, the intent filter must look like this:
<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="[YourPackageName]" />
</intent-filter>
Replace [YourPackageName]
with your android app's package name, and use [YourPackageName]:/oauth
as your redirect URL (the oauth part can be named anything)
So uh... thanks google for documenting that nowhere