Search code examples
androidappauth

Trouble Creating Android ClientID to use with AppAuth Library for Android


I want to use AppAuth-Android for openID sign in within my app.

My problem is that no matter how I create a Client ID for Android I continue to receive redirect_uri 400 errors. Adding a Client ID for Android doesnt clearly show what redirect_uri is or needs to be and when I just use the package name of my app I end up with a redirect_uri_mismatch.

Adding Client ID for Android doesnt clearly show what redirect_uri is or needs to be

I have gone through the codelabs tutorial created by google and everything seemed straightforward.

However, now that I am trying to get everything setup in my app, there is not enough detail around exactly what steps need to be taken to create a client_id and a redirect_uri that will work for the custom scheme in my app.

Here's a picture of the slide where it assumes I'll be able to correctly create a client_id: A depiction of exactly the step that I need more detail on

I have found plenty of documentation from google with advice on what to do but none of it has included enough details to get me around this issue which I have spent way too many hours on. The most useful page that I found here was the section on OAuth2 for Mobile & Desktop

Can anyone provide the exact steps to take within Google's API Credential manager to create a client_id for my existing android app that will be able to work in the exact same manner as the codelabs tutorial referenced above?


Solution

  • This turned out to be an issue with copy/pasting the client_id and I was too focused on the error message related to the redirect_uri to figure it out without taking a long break away.

    Here are some items I can clarify in case someone else ends up banging their head over the same issue.

    To resolve the redirect_uri problem I had, I went back through and made sure that:

    1. The Client ID matched the one in the google api console and that the google api console had the correct package name for my app.

      "com.examplepackagename"

    2. The custom scheme declared in my manifest matched the app's package name directly.

        <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="com.examplepackagename"/>
            </intent-filter>
        </activity>
    
    1. The redirect uri passed by the app followed the example of the code lab and was formatted like

    "com.examplepackagename:/oauth2callback"