【问题标题】:Is there a way to get access keys using user pool user and no AWS credentials有没有办法使用用户池用户和没有 AWS 凭证来获取访问密钥
【发布时间】:2019-12-27 21:53:59
【问题描述】:

我有一个 Java 后端服务,我想使用 AWS Cognito 提供对 AWS 服务的身份验证和访问。该服务没有关于 AWS 账户的任何信息。我看到所有客户端都需要 AWS 凭证或管理员凭证才能创建它们。如何在不了解 AWS 账户的情况下仅使用用户池中的用户来授予对这项服务的访问权限?

我已经尝试过客户端和服务器端,但它们都需要 aws 凭据来创建用户池和身份池客户端,然后才能获取访问令牌。

        try {
            credentials = new ProfileCredentialsProvider("default").getCredentials();
        } catch (Exception e) {
            throw new AmazonClientException(
                    "Cannot load the credentials from the credential profiles file. " +
                    "Please make sure that your credentials file is at the correct " +
                    "location (/Users/ayushaws/.aws/credentials), and is in valid format.",
                    e);
        }

        // Creating Cognito user pool client
        AWSCognitoIdentityProvider client = AWSCognitoIdentityProviderClientBuilder.standard()
                .withRegion("us-east-1")
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .build();

这就是我目前创建客户的方式。我的问题是,这最初需要我的凭据来创建客户端。如果使用的应用程序在 AWS 之外并且不知道 AWS 帐户,我们如何创建客户端。

【问题讨论】:

    标签: amazon-web-services amazon-cognito


    【解决方案1】:

    您需要使用具有足够权限的凭据来创建 Cognito 用户池和 Cognito 身份池。由于您使用的是 Cognito,您应该能够在客户端应用程序中处理身份验证和访问,并且您的应用程序不需要长期凭据,因为身份池将提供必要的凭据。

    在您的客户端应用程序中,用户将直接登录到 Cognito 用户池。当他们成功登录到用户池时,他们将收到包含IdToken 的响应。然后,您将 IdToken 添加到凭证映射中,这将授予用户访问 Identity Pools Authenticated IAM 角色允许的资源的权限。

    您可以在AWS Cognito docs 中阅读有关如何将 Cognito 用户池与 Cognito 身份池结合使用的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-07
      • 2019-04-22
      • 2018-01-21
      • 2020-12-31
      • 2018-04-28
      • 2015-03-27
      • 2019-08-31
      • 2021-08-26
      相关资源
      最近更新 更多