【问题标题】:need help understanding a code example from the AWS Amazon Cognito developer guide regarding developer provided authentication method需要帮助了解 AWS Amazon Cognito 开发人员指南中有关开发人员提供的身份验证方法的代码示例
【发布时间】:2016-08-20 07:30:32
【问题描述】:

在this page from the Amazon Cognito Developer Guide 中有一个代码示例:

idRequest.setIdentityId("14232"); <--- this line here is the line of concern
# please use Control/Command+F to find this line

更清晰的上下文的更广泛的代码视图如下:

// Create a new request to retrieve the token for your end user
GetOpenIdTokenForDeveloperIdentityRequest idRequest =
  new GetOpenIdTokenForDeveloperIdentityRequest();
idRequest.setIdentityPoolId("YOUR_COGNITO_IDENTITY_POOL_ID");
idRequest.setIdentityId("14232");

在这里,我们准备在 Amazon Cognito 客户端中首次建立新用户的身份。

现在,我试图理解为什么我们在这里调用 setIdentityId() 而(在代码的这一点)我们仍然没有 Cognito 为我们提供任何身份?我们应该用什么来设置 IdentityId?为什么这里使用"14232"?

在Amazon Cognito API 的支持 Xamarin SDK 文档中,它说

当您要创建新身份时,IdentityId 应为 null。当您想将新登录与现有的已验证/未验证身份相关联时,您可以通过提供现有 IdentityId 来实现。

我很困惑,如果文档说“identityId 应该为空”当我们试图创建一个新的身份时,那为什么官方开发者指南中的代码示例使用 14232 而不是 null?

试图弄清楚这个新的 Cognito 事物。

【问题讨论】:

    标签: amazon-web-services authentication identity amazon-cognito


    【解决方案1】:

    你是对的,当没有身份ID时应该传递空身份ID。通常,当您获取身份 ID 时,会将其传回客户端,客户端将传递您将用于填充 GetOpenIdTokenForDeveloperIdentityRequest 的相同身份 ID。

    【讨论】:

      【解决方案2】:

      从代码中,在我看来,您创建了一个带有身份 ID 的 idRequest。如果你想创建一个新的身份,你可以传递null。当您将其与现有的相关联时,您需要传递现有的identityId[在此代码中完成]。作为响应,您将返回 identityId,它在最后几行代码中再次捕获,只是为了验证请求是否成功。

      这里详细解释一下请求的参数-http://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetOpenIdTokenForDeveloperIdentity.html

      【讨论】:

      • 这个例子不是在谈论与现有的关联。它正在谈论创建一个新的。这可能是代码示例错误吗?
      猜你喜欢
      • 1970-01-01
      • 2015-01-05
      • 1970-01-01
      • 2015-04-15
      • 2014-12-05
      • 2018-12-08
      • 2017-06-02
      • 2015-10-04
      • 2016-11-21
      相关资源
      最近更新 更多