英文:
How to get user attributes using adminGetUserRequest in cognito
问题
以下是您的翻译内容:
我正在尝试使用 AdminGetUserRequest 从 Cognito 获取用户属性,以下是我的代码:
public class getUserDetails {
public static void main(String[] args) {
String app_client_id = "xxxxxxxxxxxx";
String app_client_secret = "xxxxxxxxxxx";
String user_pool_id = "xxxxxxxxx";
String region = "xxxxxxxxxx";
String AWS_ACCESS_KEY = "xxxxxxxxxx";
String AWS_SECRET_KEY = "xxxxxxxxxx";
AWSCredentials awsCreds = new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY);
AWSCognitoIdentityProvider client = AWSCognitoIdentityProviderClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.withRegion(region)
.build();
AdminGetUserRequest adminGetUserRequest = new AdminGetUserRequest()
.withUserPoolId(user_pool_id)
.withUsername("testUser");
try {
AdminGetUserResult adminGetUserResult = client.adminGetUser(adminGetUserRequest);
System.out.println(adminGetUserResult.getUserAttributes());
} catch (UserNotFoundException e) {
System.out.println("User not found");
}
}
}
代码运行正常,我可以获取到用户,但属性值显示为 Sensitive Data Redacted。我得到的输出如下:
[{Name: sub, Value: ***Sensitive Data Redacted***}, {Name: email_verified, Value: ***Sensitive Data Redacted***}, {Name: email, Value: ***Sensitive Data Redacted***}]
我该如何获取显示为 Sensitive Data Redacted 的这些值?我没有任何访问令牌,我只有用户名来检索这些值。
英文:
I am trying to get the user attributes from cognito using AdminGetUserRequest, the following is my code:
public class getUserDetails {
public static void main(String[] args) {
String app_client_id ="xxxxxxxxxxxx";
String app_client_secret ="xxxxxxxxxxx";
String user_pool_id ="xxxxxxxxx";
String region = "xxxxxxxxxx";
String AWS_ACCESS_KEY = "xxxxxxxxxx";
String AWS_SECRET_KEY = "xxxxxxxxxx";
AWSCredentials awsCreds = new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY);
AWSCognitoIdentityProvider client = AWSCognitoIdentityProviderClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.withRegion(region)
.build();
AdminGetUserRequest adminGetUserRequest = new AdminGetUserRequest()
.withUserPoolId(user_pool_id)
.withUsername("testUser");
try {
AdminGetUserResult adminGetUserResult = client.adminGetUser(adminGetUserRequest);
System.out.println(adminGetUserResult.getUserAttributes());
}catch (UserNotFoundException e) {
System.out.println("User not found");
}
}
}
The code is working fine and I am getting the user, but the attribute values are listed as Sensitive Data Redacted. The output I am getting is the following
[{Name: sub,Value: ***Sensitive Data Redacted***}, {Name: email_verified,Value: ***Sensitive Data Redacted***}, {Name: email,Value: ***Sensitive Data Redacted***}]
How do I get the values that are listed as Sensitive Data Redacted. I don't have any access tokens, I just have the username to retrieve these values.
答案1
得分: 2
我确信这只是https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cognitoidp/model/AttributeType.html的toString
方法的默认实现,以防止意外记录敏感数据。
尝试明确要求使用getValue
,我相信你会获得你的值。
英文:
I do believe this is just a default implementation of toString
method of https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cognitoidp/model/AttributeType.html to prevent unintentional log of sensitive data.
Try to explicitly ask for getValue
and I believe you will get your value.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论