1

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

很简单,我关注了这篇博文并更改了一些内容(即我不使用 DyanamoDb 表,回调是为了在 S3 存储桶内简单起见)。我试图实现的流程称为增强(简化)流程(详情请点击此处):

增强的简化流程

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

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。

4

1 回答 1

4
  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 希望这会有所帮助。
于 2017-08-26T10:16:55.603 回答