AppAuth-Android icon indicating copy to clipboard operation
AppAuth-Android copied to clipboard

AuthorizationResponse.fromIntent(intent) is null after redirected in Android app

Open RogerKoh opened this issue 8 months ago • 4 comments

Configuration

  • Version: 011.1
  • Integration: Android native(Kotlin) API 34
  • Identity provider: KeyCloak 26.1.4

Hi everyone,

Objective:

Trying to make an android app to authenticate with Keycloak using PKCE

Issue:

AuthorizationResponse.fromIntent(intent) is getting null in the app's redirectedActivity page.

Processes:

1) Android app is able to launch the keycloak login page using the following codes:

           val authRequest = AuthorizationRequest.Builder(
            serviceConfiguration,
            Config.CLIENT_ID,
            ResponseTypeValues.CODE,
            Uri.parse(Config.REDIRECT_URI)
        )
            .setCodeVerifier(codeVerifier, codeChallenge, CODE_CHALLENGE)
            .setScope(Config.SCOPE)
            .build()

        val authRequestUrl = authRequest.toUri()
        val intent = Intent(Intent.ACTION_VIEW, authRequestUrl)

        context.startActivity(intent)
        onResult(Result.success(authRequestUrl))

2) Keycloak page launched and able to login and the event in keycloak showed "LOGIN" is successful.

3) Once submitted, the redirectedPage configured in Android Manifest was triggered and able to trace that the oncreate method is called and AuthorzationResponse.fromIntent is null. Below is the code.

  override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val response = AuthorizationResponse.fromIntent(intent)   -> null
        val exception = AuthorizationException.fromIntent(intent)

      }

4) The content of the Intent is as follows:

example.com://oauth2redirect?state=-Dzehoz8zpfl7IhpXxbk2Q&session_state=b2ef796a-2638-41df-82a5-fea05977836b&iss=http%3A%2F%2F10.0.2.2%3A8080%2Frealms%2FABC&code=ce4ccbf6-4f62-45ae-8225-1065a825915b.b2ef796a-2638-41df-82a5-fea05977836b.6b4880e0-0592-4ba4-b6bb-d655e9d0a5ac

There isn't anything in the Extras.

Appreciate if anyone can highlight what is wrong? Thank you very much for your help.

RogerKoh avatar Apr 04 '25 11:04 RogerKoh

I was observing something similar. I think I fixed it by removing the Intent-filter from my AndroidManifest.xml and only kept the manifestPlaceholders in build.gradle. But now I have another issue - state in response is null.

jnorkus avatar Apr 24 '25 07:04 jnorkus

@RogerKoh / @jnorkus did you happen to find any slution?

fethij avatar Aug 06 '25 16:08 fethij

@RogerKoh / @jnorkus did you happen to find any slution?

I solved it somehow. I think I had to go deep and debug the library until I found the actual cause.

jnorkus avatar Aug 06 '25 16:08 jnorkus

You have to use FLAG_MUTABLE to allow the library to add the extras to the intent you initially defined

erik-everardo avatar Sep 12 '25 17:09 erik-everardo