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
...
}
}
}