1

I'm using AppAuth library(net.openid:appauth:0.7.1) for authenticating user in chrome custom tab.

I have two application let's say, App-A and App-B. App-A has an activity(App-A-MainActivity) which launch an activity of App-B(App-B-MainActivity). App-B-MainActivity has a button which launch custom tab for authentication for my OIDC endpoint. After successful authentication, we need to get authCode in App-B-MainActivity i.e. in onActivityResult overridden method.

Working:

In this case, I'm launching App-B-MainActivity directly, instead of launching through App-A. After successful authentication in custom tab, it is getting redirected to App-B-MainActivity and I'm able to get required authCode in onActivityResult overridden method of application App-B.

Not Working:

In this, I'm launching App-B-MainActivity from App-A-MainActivity. After successful authentication in custom tab, it is not getting redirected to App-B-MainActivity, so I'm not able to get required authCode in onActivityResult overridden method of application App-B.

So, is there anything that I'm missing in second scenario or is there something related to context(applicationContext) I'm providing in AuthorizationService ?

Please help me with anything that can help me solving this issue.

Here is my AuthApp code to launch custom tab for authentication (in Kotlin):

val authenticate_button = findViewById<Button>(R.id.authenticate_button)
authenticate_button.setOnClickListener {

    val authServiceConfig = AuthorizationServiceConfiguration(
        Uri.parse(COGNITO_AUTH_ENDPOINT),
        Uri.parse(COGNITO_TOKEN_ENDPOINT)
    )
    val authRequestBuilder = AuthorizationRequest.Builder(
        authServiceConfig, CLIENT_ID,
        ResponseTypeValues.CODE, Uri.parse(REDIRECT_URI)
    )
    val authRequest = authRequestBuilder.setScope("openid").build()

    val appAuthConfig = AppAuthConfiguration.Builder().setBrowserMatcher(
        BrowserWhitelist(VersionedBrowserMatcher.CHROME_CUSTOM_TAB)
    ).build()
    val authService = AuthorizationService(applicationContext, appAuthConfig)

    startActivityForResult(authIntent, RC_AUTH)
}

Overriden onActivityResult method:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)

    if (requestCode == RC_AUTH && data != null) {
        val resp = AuthorizationResponse.fromIntent(data)
        if (resp != null && resp.authorizationCode != null) {
            // auth code
            val authCode = resp.authorizationCode
            ...
        }
    }
}
Enigma
  • 179
  • 2
  • 12

1 Answers1

1

Please note below is hit and trial solution.

It appears that net.openid:appauth:0.7.1 is buggy. Please have a look at this question or this (My) question. I also started with 0.7.1 and after spending 6 days I stumbled upon the question asked by @Kerry.

After trying everything I thought why not try this as well. So I changed my version and voila "It worked", maybe this is the issue in your situation too. Please also let me know if it worked.

Karan
  • 752
  • 2
  • 13
  • 34
  • Yes, appauth IS buggy! I've been experiencing all sorts of weird issues that either appear of disappear, depending on the version. And all example code I've found doesn't work as it was depends on some specific things which have changed, been 'fixed', or now have bugs. Bleh. – SMBiggs Nov 16 '20 at 15:43