I've been trying to implement Google's AppAuth library in Android but I'm struggling to get this working. I've been trying to follow the guide from Google and apply that to my own codebase but I'm stuck around the pending intents.
More specifically, when I call the performAuthorizationRequest()
method, the emulator can follow the redirect to obtain the auth code in it's custom tab (I can see it). However, no handler is being called. I've tried adding onNewIntent()
, onActivityResult()
and onResume()
but none of them are being called.
From the Javadocs from performAuthorizationRequest()
, I see that
"the provided {@link PendingIntent completion PendingIntent} will be invoked".
What does that mean? How can I interact with the completed pendingIntent object? Is there any way that I can retrieve that context using the request code send when the pending intent was being created?
Here's my code below:
var authReq: AuthorizationRequest = AuthorizationRequest.Builder(
serverConfig,
clientId,
ResponseTypeValues.CODE,
redirectUri
).build()
val service: AuthorizationService = AuthorizationService(view.context)
val action = "com.google.codelabs.appauth.HANDLE_AUTHORIZATION_RESPONSE"
val authIntent = Intent(action)
val pendingIntent = PendingIntent.getActivity(this, authReq.hashCode(), authIntent, 0)
service.performAuthorizationRequest(authReq, pendingIntent)
Inside my manifest, I've added the activities:
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.google.codelabs.appauth.HANDLE_AUTHORIZATION_RESPONSE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name="net.openid.appauth.RedirectUriReceiverActivity" >
<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.google.codelabs.appauth"/>
</intent-filter>
</activity>
Ok, so after spending a few more days on this, I realized that I messed up the redirect URI and the data elements for the RedirectUriReceiverActivity. Somehow, this resource helped me understand what I was missing.
Inside the AndroidManifest.xml, the RedirectUriReceiverActivity needs to know where to send the completion back. Also my redirect uri (inside my authReq) was set to an external address, I changed it to using an Android deeplink.