【问题标题】:"The AWS Access Key Id you provided does not exist in our records" during a federation with Salesforce在与 Salesforce 联合期间,“您提供的 AWS 访问密钥 ID 不存在于我们的记录中”
【发布时间】:2018-02-03 15:04:23
【问题描述】:

我正在尝试通过这种方式在 Amazon 和 Salesforce 之间建立联合:如果用户通过 Salesforce 正确进行身份验证,它将看到给定帐户中的所有 S3 存储桶。

很简单,我关注 this blog post 并更改了一些内容(即我不使用 DyanamoDb 表,回调是为了简单起见在 S3 存储桶中)。我试图实现的流程称为增强(简化)流程(详情here):

相比文章,我稍微修改了回调代码:

function onPageLoad() {
    var url = window.location.href;
    var match = url.match('id_token=([^&]*)');
    var id_token = "";

    if (match) {
        id_token = match[1];
    } else {
        console.error("Impossibile recuperare il token");
    }

    AWS.config.region = "eu-west-1"
    const cognitoParams = {
        AccountId: "ACC_ID",
        IdentityPoolId: "eu-west-1:XXX",
        Logins: {
            "login.salesforce.com": id_token
        }
    }

    const identity = new AWS.CognitoIdentity()

    identity.getId(cognitoParams, function (err, identityData) {
        if (err) {
            printMessage(err);
            return;
        }

        const identityParams = {
            IdentityId: identityData.IdentityId,
            Logins: cognitoParams.Logins
        }

        identity.getCredentialsForIdentity(identityParams, function (err, data) {
            if (err) {
                printMessage(err);
            } else {
                var c = {
                    region: 'eu-west-1',
                    accessKeyId: data.Credentials.AccessKeyId,
                    secretAccessKey: data.Credentials.SecretKey
                };
                var s3 = new AWS.S3(c);

                // HERE IS THE ERRORE - data is empty and response contains the error
                s3.listBuckets((response, data) => {
                    data.Buckets.forEach(function (value) { appendMessage(value.Name) })
                });
            }
        });
    });

    // IRRELEVANT CODE
}

我可以从 Salesforce 获取令牌,我可以获取访问密钥和密钥,但是当我尝试列出存储桶时,我得到一个简洁的:

我们的记录中不存在您提供的 AWS 访问密钥 ID。

我发现这个错误是合理的,因为我根本没有用户并且密钥是即时创建的。我在哪里可以打我的头? SDK 为 2.103.0。

【问题讨论】:

    标签: javascript amazon-web-services amazon-s3 aws-sdk-js


    【解决方案1】:
    1. 可能是由于 IAM 的最终一致性,您能否尝试在调用 listbucket api 或向 us-east-1 端点发出请求之前添加延迟?
      http://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_general.html#troubleshoot_general_access-denied-service2

      1. GetCredentialsForIdentity 返回临时凭据。因此,您应该包括 AccessKeyId、SecretKey 和 SessionToken 来发出请求。 http://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html 希望这会有所帮助。

    【讨论】:

    • 这是第二个。临时凭证关联的 AccessKeyId 没有任何意义,除非附带 SessionToken,会导致这个错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 2017-10-10
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多