-
Notifications
You must be signed in to change notification settings - Fork 125
Description
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
Language and Async Model
Kotlin - Coroutines
Amplify Categories
Authentication
Gradle script dependencies
Amplify version: 2.30.4
Dependencies:
aws-amplify-auth-cognito = { group = "com.amplifyframework", name = "aws-auth-cognito", version.ref = "aws-amplify" }
aws-amplify-core-kotlin = { group = "com.amplifyframework", name = "core-kotlin", version.ref = "aws-amplify" }Environment information
Details
Build time: 2025-02-25 09:22:14 UTC
Revision: 073314332697ba45c16c0a0ce1891fa6794179ff
Kotlin: 2.0.21
Groovy: 3.0.22
Ant: Apache Ant(TM) version 1.10.15 compiled on August 25 2024
Launcher JVM: 17.0.2 (Oracle Corporation 17.0.2+8-LTS-86)
Daemon JVM: C:\Program Files\Java\jdk-17.0.2
Please include any relevant guides or documentation you're referencing
No response
Describe the bug
The user can sign in successfully using SSO on the first attempt without any issues.
After logging in, when the user taps Sign Out in the app, we call Amplify.Auth.signOut(). The sign-out completes successfully and returns AWSCognitoAuthSignOutResult.CompleteSignOut (see annotation 1 below).
The user is then redirected to the login screen. However, when attempting to sign in again using the same SSO flow, the following error is returned:
UserCancelledException{
message=The user cancelled the sign-in attempt, so it did not complete.,
cause=null,
recoverySuggestion=To recover: catch this error, and show the sign-in screen again.
}
(see annotation 2 below).
During the second login attempt, a WebView seems to briefly open and immediately closes.
This appears similar to issue #2591, but adding a delay does not resolve the problem.
Reproduction steps
- Log in using SSO via
Amplify.Auth.signInWithSocialWebUI(provider: AuthProvider, callingActivity: Activity, options: AuthWebUISignInOptions) - Login succeeds.
- Log out by calling
Amplify.Auth.signOut(global = false). - Attempt to log in again using the same SSO method.
- A
UserCancelledExceptionis thrown.
Debugging Details
I added breakpoints in both CustomTabsManagerActivity.kt and HostedUIRedirectActivity.kt to investigate the flow.
First Login (Works as Expected)
- User enters an email in the app, we check if is SSO login. If is SSO, we call
signInWithSocialWebUI(provider: AuthProvider, callingActivity: Activity, options: AuthWebUISignInOptions) CustomTabsManagerActivity.onCreateis calledCustomTabsManagerActivity.onResumeis called (customTabsLaunched == false).- A Webview is opened showing SSO login page. User enters email and password. User logs in sucessfully.
HostedUIRedirectActivity.onCreateis called.HostedUIRedirectActivity.onResumeis called, which invokesAmplify.Auth.handleWebUISignInResponse(intent), thenfinish().CustomTabsManagerActivity.onResumeis called again (customTabsLaunched == true) with a non-nullintent.datacontaining the callback URL.- User clicks the log-out button in the app. App calls
Amplify.Auth.signOut(global = false) CustomTabsManagerActivity.onCreatedis calledCustomTabsManagerActivity.onResumeis called (customTabsLaunched == false)- A Webview is opened and closed quickly.
HostedUIRedirectActivity.onCreatedis called.HostedUIRedirectActivity.onResumeis called, which invokesAmplify.Auth.handleWebUISignInResponse(intent), thenfinish().
Second Login (After Logout – Fails)
- User enters an email in the app, we check if it is SSO login. If is SSO, we call
signInWithSocialWebUI(provider: AuthProvider, callingActivity: Activity, options: AuthWebUISignInOptions) CustomTabsManagerActivity.onCreateis calledCustomTabsManagerActivity.onResumeis called (customTabsLaunched == false).- No sure if a WebView is open.
HostedUIRedirectActivityis not created. CustomTabsManagerActivity.onResumeis called immediately (customTabsLaunched == true) withintent.data == null.- This results in the sign-in being treated as cancelled, triggering
UserCancelledException.
It’s unclear why HostedUIRedirectActivity is skipped on the second login attempt after a successful sign-out.
Code Snippet
SSO Login
private suspend fun performSignIn(authProviderName: String, activity: androidx.appcompat.app.AppCompatActivity): Result<SSOLoginData> {
val result = Amplify.Auth.signInWithSocialWebUI(
provider = AuthProvider.custom(authProviderName),
callingActivity = activity,
AWSCognitoAuthWebUISignInOptions.builder()
.preferPrivateSession(true)
.build()
)
if (!result.isSignedIn) {
error("AuthSignInResult.isSignedIn is false")
}
val ssoLoginData = extractSSOLoginData(
fetchAmplifyAuthState().getOrThrow()
)
Timber.d("SSO login with Web UI succeeded: $ssoLoginData")
return Result.success(ssoLoginData)
}
Callback activity configuration
<activity
android:name="com.amplifyframework.auth.cognito.activities.HostedUIRedirectActivity"
android:exported="true">
<intent-filter android:label="SSO Login">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="app"
android:pathPrefix="/sign-in"
android:scheme="thrive" />
</intent-filter>
<intent-filter android:label="SSO Logout">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="app"
android:pathPrefix="/sign-out"
android:scheme="thrive" />
</intent-filter>
</activity>