缺少身份验证令牌错误,尝试从Cognito获取用户详细信息。

huangapple go评论68阅读模式
英文:

Missing Authentication Token error while trying to fetch user details from cognito

问题

以下是您提供的代码的翻译部分:

我正在尝试使用用户名从 Cognito 中获取用户详细信息但我遇到了这个错误

    Exception in thread "main" com.amazonaws.services.cognitoidp.model.AWSCognitoIdentityProviderException: 缺少身份验证令牌服务AWSCognitoIdentityProvider状态码400错误代码MissingAuthenticationTokenException请求ID2b5226c1-49cc-4d55-bafe-08b371d38b50代理null
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1811)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleServiceErrorResponse(AmazonHttpClient.java:1395)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1371)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1145)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:802)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:770)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:744)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:704)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:686)
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:550)
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:530)
	at com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClient.doInvoke(AWSCognitoIdentityProviderClient.java:7825)
	at com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClient.invoke(AWSCognitoIdentityProviderClient.java:7792)
	at com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClient.invoke(AWSCognitoIdentityProviderClient.java:7781)
	at com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClient.executeAdminGetUser(AWSCognitoIdentityProviderClient.java:1307)
	at com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClient.adminGetUser(AWSCognitoIdentityProviderClient.java:1278)
	at getUserDetails.main(getUserDetails.java:24)

以下是我的代码

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProvider;
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClientBuilder;
import com.amazonaws.services.cognitoidp.model.AdminGetUserRequest;
import com.amazonaws.services.cognitoidp.model.AdminGetUserResult;

public class getUserDetails {

    public static void main(String[] args) {
        String app_client_id = "xxxxxxxx";
        String app_client_secret = "xxxxxxxx";
        String user_pool_id = "xxxxxxxx";
        String region = "xxxxxxxx";
        AnonymousAWSCredentials awsCreds = new AnonymousAWSCredentials();
        AWSCognitoIdentityProvider client = AWSCognitoIdentityProviderClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
                .withRegion(region)
                .build();

        AdminGetUserRequest adminGetUserRequest = new AdminGetUserRequest()
                .withUserPoolId("user_pool_id")
                .withUsername("Facebook_10223918658622607");
        AdminGetUserResult adminGetUserResult = client.adminGetUser(adminGetUserRequest);

    }
}
这是否需要任何管理员凭据如果是这样我该如何输入还有其他实现此目的的方法吗

如果您需要进一步的帮助,请随时提问。

英文:

I am trying to fetch user details from cognito using username but i am getting this error

Exception in thread "main" com.amazonaws.services.cognitoidp.model.AWSCognitoIdentityProviderException: Missing Authentication Token (Service: AWSCognitoIdentityProvider; Status Code: 400; Error Code: MissingAuthenticationTokenException; Request ID: 2b5226c1-49cc-4d55-bafe-08b371d38b50; Proxy: null)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1811)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleServiceErrorResponse(AmazonHttpClient.java:1395)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1371)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1145)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:802)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:770)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:744)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:704)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:686)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:550)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:530)
at com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClient.doInvoke(AWSCognitoIdentityProviderClient.java:7825)
at com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClient.invoke(AWSCognitoIdentityProviderClient.java:7792)
at com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClient.invoke(AWSCognitoIdentityProviderClient.java:7781)
at com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClient.executeAdminGetUser(AWSCognitoIdentityProviderClient.java:1307)
at com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClient.adminGetUser(AWSCognitoIdentityProviderClient.java:1278)
at getUserDetails.main(getUserDetails.java:24)

The following is my code:

    import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProvider;
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClientBuilder;
import com.amazonaws.services.cognitoidp.model.AdminGetUserRequest;
import com.amazonaws.services.cognitoidp.model.AdminGetUserResult;
public class getUserDetails {
public static void main(String[] args) {
String app_client_id ="xxxxxxxx";
String app_client_secret ="xxxxxxxx";
String user_pool_id ="xxxxxxxx";
String region = "xxxxxxxx";
AnonymousAWSCredentials awsCreds = new AnonymousAWSCredentials();
AWSCognitoIdentityProvider client = AWSCognitoIdentityProviderClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.withRegion(region)
.build();
AdminGetUserRequest adminGetUserRequest = new AdminGetUserRequest()
.withUserPoolId("user_pool_id")
.withUsername("Facebook_10223918658622607");
AdminGetUserResult adminGetUserResult = client.adminGetUser(adminGetUserRequest);
}
}

does this require any admin credentials to do this? if so how do i input that? Is there any other way to achieve this?

答案1

得分: 0

public class getUserDetails {

    public static void main(String[] args) {
        String app_client_id = "xxxxxxxxxxx";
        String app_client_secret = "xxxxxxxxxxxxxxx";
        String user_pool_id = "xxxxxxxxxxxx";
        String region = "xxxxxxxxxxxxxxxx";
        String AWS_ACCESS_KEY = "xxxxxxxxxxxxxxxxxxxx";
        String AWS_SECRET_KEY = "xxxxxxxxxxxxxxxxxxxx";
        // AnonymousAWSCredentials awsCreds = new AnonymousAWSCredentials();
        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("abcd");

        try {
            AdminGetUserResult adminGetUserResult = client.adminGetUser(adminGetUserRequest);
        } catch (UserNotFoundException e) {
            System.out.println("User not found");
        }
    }
}

对于任何需要这个答案的人,我们需要提供 AWS_ACCESS_KEY、AWS_SECRET_KEY,以便能够使用 AdminGetUserRequest。

英文:
public class getUserDetails {
public static void main(String[] args) {
String app_client_id ="xxxxxxxxxxx";
String app_client_secret ="xxxxxxxxxxxxxxx";
String user_pool_id ="xxxxxxxxxxxx";
String region = "xxxxxxxxxxxxxxxx";
String AWS_ACCESS_KEY = "xxxxxxxxxxxxxxxxxxxx";
String AWS_SECRET_KEY = "xxxxxxxxxxxxxxxxxxxx";
//        AnonymousAWSCredentials awsCreds = new AnonymousAWSCredentials();
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("abcd");
try {
AdminGetUserResult adminGetUserResult = client.adminGetUser(adminGetUserRequest);
}catch (UserNotFoundException e) {
System.out.println("User not found");
}
}
}

For anyone that is looking for an answer to this, we have to provide AWS_ACCESS_KEY, AWS_SECRET_KEY to able to use AdminGetUserRequest

huangapple
  • 本文由 发表于 2020年9月16日 04:18:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/63909292.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定