Authentication Activity
    Handles OAuth sign-in and Identity-Aware Proxy (IAP) sign-in/sign-out flows by launching a Custom Tab for user interaction.
This activity must be registered in the application's manifest. Configuration depends on the app's requirements:
For authentication challenges where the Custom Tab redirects back to this activity:
Declare the activity with
launchMode="singleTop"and include anintent-filter:
<activity
android:name="com.arcgismaps.toolkit.authentication.AuthenticationActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:exported="true"
android:launchMode="singleTop" >
<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:host="auth"
android:scheme="my-ags-app" />
</intent-filter>
</activity>Content copied to clipboardIf the redirect intent should be handled by another activity:
Remove the
AuthenticationActivityfrom your app's manifest and put its intent filter on the activity that you wish to receive the redirect intent.Set your activity's
launchModetosingleTop, this must be done in order for OAuth or IAP redirect to work.
<activity
...
android:launchMode="singleTop"
... >
<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:host="auth"
android:scheme="my-ags-app" />
</intent-filter>
...Content copied to clipboardCall the extension function
launchCustomTabsin the lambdaonPendingBrowserAuthenticationChallengeof theAuthenticator, passing in the pendingBrowserAuthenticationChallenge:
DialogAuthenticator(
authenticatorState = authenticatorState,
onPendingBrowserAuthenticationChallenge = { pendingBrowserAuthenticationChallenge ->
launchCustomTabs(pendingBrowserAuthenticationChallenge)
}
)Content copied to clipboardHandle the redirect in your app activity's
onNewIntentandonResumeoverrides:You can check if the
intentwas caused by an OAuth or IAP redirect because theintent.data.toString()will start with your OAuth or IAP configuration's redirect URI.Currently, IAP sign-out does not redirect back to the app, so you will not receive an intent in
onNewIntent. Instead, this will need to be handled inonResumewhen the Custom Tab is closed. See documentation of AuthenticatorState.completeBrowserAuthenticationChallenge for more details.
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intent?.data?.toString()?.let { redirectUri ->
if (redirectUri.startsWith("your-redirect-uri")) {
// This gets called when OAuth or IAP redirects back to the app.
authenticationAppViewModel.authenticatorState.completeBrowserAuthenticationChallenge(intent)
}
}
}
override fun onResume() {
super.onResume()
// This gets called when the Custom Tab is closed using the close button or the phone's back button, so we
// pass null.
if (viewModel.isCustomTabLaunched()) {
authenticationAppViewModel.authenticatorState.completeBrowserAuthenticationChallenge(null)
}
}Content copied to clipboardSee ../README.md for more details.
Since
200.8.0