【问题标题】:Amazon Cognito connection cannot find IdentityPoolAmazon Cognito 连接找不到 IdentityPool
【发布时间】:2015-01-24 01:57:13
【问题描述】:

我花了一天时间试图让 Cognito 在我的服务器上运行。我没有找到任何有帮助的文档,因为没有明确的设置示例。

我的服务器上有以下代码:

BasicAWSCredentials credentials = new BasicAWSCredentials(
        "A**************",
        "+y*****************************");

AmazonCognitoIdentityClient client =
        new AmazonCognitoIdentityClient(credentials);
GetOpenIdTokenForDeveloperIdentityRequest tokenRequest =
        new GetOpenIdTokenForDeveloperIdentityRequest();
tokenRequest.setIdentityPoolId("eu-west-1:be9d19a5-*******************");
HashMap<String, String> map = new HashMap<String, String>();

//Key -> Developer Provider Name used when creating the identity pool
//Value -> Unique identifier of the user in your <u>backend</u>
map.put("access.com.cbn.postref", "fred");

//Duration of the generated OpenID Connect Token
tokenRequest.setLogins(map);
tokenRequest.setTokenDuration(1000l);

GetOpenIdTokenForDeveloperIdentityResult result = client
        .getOpenIdTokenForDeveloperIdentity(tokenRequest);
String identityId = result.getIdentityId();
String token = result.getToken();

System.out.println("id = " + identityId + "  token = " + token);

我创建了一个 IAM 用户并在上面的代码中使用了公钥和私钥。我使用 Dev 在 Cognito 上创建了一个 IndentityPool。授权。代码中给出的 ID:access.com.cbn.postref。

当我运行这段代码时,我得到一个异常:

com.amazonaws.services.cognitoidentity.model.ResourceNotFoundException: 未找到 IdentityPool 'eu-west-1:be9d19a5-****************************'。 (服务:AmazonCognitoIdentity;状态码:400

生成于

GetOpenIdTokenForDeveloperIdentityResult result = client
                .getOpenIdTokenForDeveloperIdentity(tokenRequest);

我完全不知道该怎么做,因为我看不出我做错了什么。我确实尝试获取 IdentityPools 列表,但返回的列表大小为 0。

【问题讨论】:

    标签: java amazon-web-services token amazon-cognito


    【解决方案1】:

    访问 eu-west-1 区域中的身份池时,您必须明确设置客户端的区域以使用该区域:

    client.setRegion(Region.getRegion(Regions.EU_WEST_1)); 
    

    我们目前正在开发一个示例开发者身份验证身份后端以及我们希望很快发布的 iOS/Android 应用程序。

    【讨论】:

    • 谢谢 Bob - 这很有效,如果你没有指出,我不会知道这一点。还有一个问题。看起来我只需要创建一个具有适当权限的用户即可访问 S3。我想我使用这个用户,我的应用程序的每个用户都会获得一个不同的连接令牌。这是正确的过程,还是我必须为在我的服务器上注册的每个应用程序用户创建一个新的 IAM 用户?
    • @cbn 您应该为每个访问您的应用程序的用户使用唯一标识符,以便他们获得唯一的认知身份 ID。否则,您的用户将能够访问彼此的数据。需要明确的是,这是您系统中的标识符。您无需在 IAM 或 Cognito 中创建任何其他资产即可完成这项工作。
    猜你喜欢
    • 1970-01-01
    • 2016-05-26
    • 2016-05-10
    • 1970-01-01
    • 2015-05-13
    • 2013-01-10
    • 2018-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多