-
Notifications
You must be signed in to change notification settings - Fork 127
Open
Labels
authRelated to the Auth category/pluginsRelated to the Auth category/pluginsfeature-requestRequest a new featureRequest a new feature
Description
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
Language and Async Model
Java
Amplify Categories
Authentication
Gradle script dependencies
def aws_amplify_version = '2.30.1'
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")
implementation "com.amplifyframework:aws-api:$aws_amplify_version"
implementation "com.amplifyframework:aws-auth-cognito:$aws_amplify_version"
implementation "com.amplifyframework:core:$aws_amplify_version"
Environment information
------------------------------------------------------------
Gradle 8.14.2
------------------------------------------------------------
Build time: 2025-06-05 13:32:01 UTC
Revision: 30db2a3bdfffa9f8b40e798095675f9dab990a9a
Kotlin: 2.0.21
Groovy: 3.0.24
Ant: Apache Ant(TM) version 1.10.15 compiled on August 25 2024
Launcher JVM: 17.0.12 (Oracle Corporation 17.0.12+8-LTS-286)
Daemon JVM: E:\Programare\jdk-17.0.12 (no JDK specified, using current Java home)
OS: Windows 11 10.0 amd64
Please include any relevant guides or documentation you're referencing
No response
Describe the bug
Auth.getCurrentUser returns user sub even if user logged in with email.
The AWS Mobile Client was returning the email in such cases. The javadoc said:
/**
* Returns the username attribute of the current access token. Note that the value stored in the username
* attribute of the access token may vary depending on how sign-in was performed. For example, if the user signed in
* with email, the username attribute will have the email address.
* @return The username attribute of the current access token.
* @see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-with-identity-providers.html#amazon-cognito-user-pools-using-the-access-token">Using the Access Token</a>
* from Cognito documentation.
*/
@AnyThread
public String getUsername() {
try {
if (userpoolsLoginKey.equals(mStore.get(PROVIDER_KEY))) {
return userpool.getCurrentUser().getUserId();
}
return null;
} catch (Exception e) {
return null;
}
}
Reproduction steps (if applicable)
No response
Code Snippet
CompletableFuture<String> future = new CompletableFuture<>();
Amplify.Auth.getCurrentUser(
user -> future.complete(user.getUsername()),
authException -> future.complete(null)
);
Both the user id and the username attributes in AuthUser are the user sub, regardless of how the user logged in.
Log output
// Put your logs below this line
Configuration File
No response
GraphQL Schema
// Put your schema below this line
Additional information and screenshots
No response
Metadata
Metadata
Assignees
Labels
authRelated to the Auth category/pluginsRelated to the Auth category/pluginsfeature-requestRequest a new featureRequest a new feature