Page updated Nov 8, 2023

Enable sign-out

Amplify Android v1 is now in Maintenance Mode until May 31st, 2024. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v1.

Please use the latest version (v2) of Amplify Library for Android to get started.

If you are currently using v1, follow these instructions to upgrade to v2.

Amplify libraries should be used for all new cloud connected applications. If you are currently using the AWS Mobile SDK for Android, you can access the documentation here.

Invoke the signOut api to sign out a user from the Auth category. You can only have one user signed in at a given time.

1Amplify.Auth.signOut(
2 () -> Log.i("AuthQuickstart", "Signed out successfully"),
3 error -> Log.e("AuthQuickstart", error.toString())
4);
1Amplify.Auth.signOut(
2 { Log.i("AuthQuickstart", "Signed out successfully") },
3 { Log.e("AuthQuickstart", "Sign out failed", it) }
4)
1try {
2 Amplify.Auth.signOut()
3 Log.i("AuthQuickstart", "Signed out successfully")
4} catch (error: AuthException) {
5 Log.e("AuthQuickstart", "Sign out failed", error)
6}
1RxAmplify.Auth.signOut()
2 .subscribe(
3 () -> Log.i("AuthQuickstart", "Signed out successfully"),
4 error -> Log.e("AuthQuickstart", error.toString())
5 );

Calling signOut without any options will just delete the local cache and keychain of the user. If you would like to sign out of all devices, invoke the signOut api with advanced options.

Amazon Cognito now supports token revocation and the latest Amplify version will revoke Amazon Cognito tokens if the application is online. This means that the Cognito refresh token cannot be used anymore to generate new Access and Id Tokens.

Access and Id Tokens are short-lived (60 minutes by default but can be set from 5 minutes to 1 day). After revocation, these tokens cannot be used with Cognito User Pools anymore. However, they are still valid when used with other services like AppSync or API Gateway.

For limiting subsequent calls to these other services after invalidating tokens, we recommend lowering token expiration time for your app client in the Cognito User Pools console. If you are using the Amplify CLI this can be accessed by running amplify console auth.

Token revocation is enabled automatically on new Amazon Cognito User Pools, however existing User Pools must enable this feature, using the Cognito Console or AWS CLI.

1Amplify.Auth.signOut(
2 AuthSignOutOptions.builder().globalSignOut(true).build(),
3 () -> Log.i("AuthQuickstart", "Signed out globally"),
4 error -> Log.e("AuthQuickstart", error.toString())
5);
1val options = AuthSignOutOptions.builder()
2 .globalSignOut(true)
3 .build()
4Amplify.Auth.signOut(options,
5 { Log.i("AuthQuickstart", "Signed out globally") },
6 { Log.e("AuthQuickstart", "Sign out failed", it) }
7)
1val options = AuthSignOutOptions.builder()
2 .globalSignOut(true)
3 .build()
4try {
5 Amplify.Auth.signOut(options)
6 Log.i("AuthQuickstart", "Signed out globally")
7} catch (error: AuthException) {
8 Log.e("AuthQuickstart", "Sign out failed", error)
9)
1RxAmplify.Auth.signOut(AuthSignOutOptions.builder().globalSignOut(true).build())
2 .subscribe(
3 () -> Log.i("AuthQuickstart", "Signed out globally"),
4 error -> Log.e("AuthQuickstart", error.toString())
5 );

Calling signout with globalSignOut = true will invalidate all the Cognito User Pool tokens of the signed in user. If the user is signed into a device, they won't be authorized to perform a task that requires a valid token when a global signout is called from some other device. They need to sign in again to get valid tokens.

Global signout functionality does not work if you use one of the web UI sign in methods.