AWS Cognito 错误:“identityPoolId"未能满足约束 [英] AWS Cognito Error: 'identityPoolId' failed to satisfy constraint

查看:26
本文介绍了AWS Cognito 错误:“identityPoolId"未能满足约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的 Cognito.我正在尝试使用 Lambda 实现 AWS Cognito.这是我正在关注的

这是 JUnit 测试

公共类AuthenticateUser实现RequestHandler{@覆盖公共对象句柄请求(对象输入,上下文上下文){AuthenticateUserResponse authenticationUserResponse = new AuthenticateUserResponse();@SuppressWarnings("未选中")LinkedHashMap inputHashMap = (LinkedHashMap)input;用户用户 = authenticationUser(inputHashMap);返回空;}公共用户身份验证用户(LinkedHashMap 输入){用户 user = null;String userName = (String) input.get("userName");String passwordHash = (String) input.get("passwordHash");尝试 {AmazonDynamoDBClient 客户端 = 新 AmazonDynamoDBClient();client.setRegion(Region.getRegion(Regions.US_EAST_1));DynamoDBMapper 映射器 = 新的 DynamoDBMapper(客户端);user = mapper.load(User.class, userName);如果(用户!= null){System.out.println("找到用户");if(user.getPasswordHash().equals(passwordHash)){System.out.println("用户密码匹配");String openIdToken = getOpenIdToken(user.getUserId());user.setOpenIdToken(openIdToken);返回用户;} 别的 {System.out.println("密码不匹配");}} 别的 {System.out.println("找不到用户");}} 捕获(异常 e){System.out.println("错误:" + e.toString());}返回用户;}

这是输出

用户找到用户密码匹配

但我收到以下错误,因此 return user 语句失败

检测到 1 个验证错误:值 'us-east-1_XXXXXX' at 'identityPoolId'未能满足约束:成员必须满足正则表达式模式:[w-]+:[0-9a-f-]+(服务:AmazonCognitoIdentity;状态代码:400;错误代码:ValidationException;

解决方案

您正在使用 Cognito 用户池 ID 作为身份池 ID.他们是两个不同的东西.身份池 ID 的格式为 us-east-1:XXXX-XXXXXX-XXXX-XXXX.

要获取身份池 ID,您应该使用 Cognito 控制台的管理联合身份"部分,而不是管理用户池"部分.希望这会有所帮助.

I am new Cognito. I am trying to implement AWS Cognito using Lambda. This is the tutorial I am following.

AmazonCognitoIdentityClient client =
                new AmazonCognitoIdentityClient();
    GetOpenIdTokenForDeveloperIdentityRequest tokenRequest = new GetOpenIdTokenForDeveloperIdentityRequest();
    tokenRequest.setIdentityPoolId("us-east-1_XXXXXXX");

This is the pool Id that I am using in the setIdentityPoolId

This is the JUnit test

public class AuthenticateUser implements RequestHandler<Object, Object> {

@Override
public Object handleRequest(Object input, Context context) {

    AuthenticateUserResponse authenticateUserResponse = new AuthenticateUserResponse();
    @SuppressWarnings("unchecked")
    LinkedHashMap inputHashMap = (LinkedHashMap)input;
    User user = authenticateUser(inputHashMap);
    return null;
}

public User authenticateUser(LinkedHashMap input){
    User user = null;
    String userName = (String) input.get("userName");
    String passwordHash = (String) input.get("passwordHash");

    try {
        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        client.setRegion(Region.getRegion(Regions.US_EAST_1));
        DynamoDBMapper mapper = new DynamoDBMapper(client);
        user = mapper.load(User.class, userName);

        if(user != null){
            System.out.println("user found");
            if(user.getPasswordHash().equals(passwordHash)){
                System.out.println("user password matched");
                String openIdToken = getOpenIdToken(user.getUserId());
                user.setOpenIdToken(openIdToken);
                return user;
            } else {
                System.out.println("password unmatched");
            }
        } else {
            System.out.println("user not found");
        }
    } catch (Exception e) {
        System.out.println("Error: " + e.toString());
    }

    return user; 
}

This is the output

user found
user password matched

But I am getting the following error and hence, the return user statement is failing

1 validation error detected: Value 'us-east-1_XXXXXX' at 'identityPoolId' 
failed to satisfy constraint: Member must satisfy regular expression pattern: [w-]+:[0-9a-f-]+ 
(Service: AmazonCognitoIdentity; Status Code: 400; Error Code: ValidationException; 

解决方案

You are using a Cognito user pool id as the identity pool id. They are two different things. Identity pool ids are of format us-east-1:XXXX-XXXXXX-XXXX-XXXX.

To get an identity pool id you should use the "Manage Federated Identities" parts of the Cognito console not the "Manage User Pools" section. Hope this helps.

这篇关于AWS Cognito 错误:“identityPoolId"未能满足约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆