【问题标题】:AWS Cognito Error: 'identityPoolId' failed to satisfy constraintAWS Cognito 错误:“identityPoolId”未能满足约束
【发布时间】:2016-09-10 11:00:52
【问题描述】:

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

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

这是我在 setIdentityPoolId 中使用的池 ID

这是 JUnit 测试

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; 
}

这是输出

user found
user password matched

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

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; 

【问题讨论】:

    标签: amazon-web-services amazon-cognito


    【解决方案1】:

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

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

    【讨论】:

    • @Chetan- 我认为您应该使用对此答案的支持作为反馈,以使本教程比身份池的“管理联合身份”更好、更好的名称
    • @Chetan 您如何从用户池 ID 中获取身份池 ID?或者获取与 cognito 用户关联的当前角色?
    • 还有返回用户池信息的describeUserPool:docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/…
    【解决方案2】:

    请注意:您还可以在项目的 aws-exports.js 中找到正确的用户池应用程序客户端 ID。属性名称为“aws_user_pools_web_client_id”

    【讨论】:

      【解决方案3】:

      你可以在User Pools > Federated Identities > App clients > App client id 找到它

      【讨论】:

        猜你喜欢
        • 2016-02-27
        • 1970-01-01
        • 1970-01-01
        • 2020-07-24
        • 1970-01-01
        • 1970-01-01
        • 2016-12-27
        • 1970-01-01
        • 2015-08-24
        相关资源
        最近更新 更多