尝试同步()到亚马逊认知时获得403(禁止)

时间:2016-04-18 21:05:16

标签: javascript facebook amazon-iam amazon-cognito

我可以登录Facebook,获取访问令牌并使用它来访问我在amazon cognito的身份池。当我尝试使用amazon同步()我的本地数据集时,我收到错误Failed to load resource: the server responded with a status of 403 (Forbidden)

它遵循亚马逊documentation,但我必须缺少一些凭据,因为它不起作用。在chrome中,我收到消息 {"message":"Missing Authentication Token"},清楚地表明了这一点。

但是sync manager github repo没有显示如何添加除池ID之外的更多凭据。

function facebookSignIn(accessToken) {
    AWS.config.update({
        region: 'eu-west-1',
        credentials: new AWS.CognitoIdentityCredentials({
            IdentityPoolId: learnjs.poolId,
            Logins: {
                'graph.facebook.com': accessToken
            }
        })
    });

    AWS.config.credentials.get(function() {
        var client = new AWS.CognitoSyncManager();
        client.openOrCreateDataset('Timebooking', function(err, dataset) {
            dataset.put('1', 'En', function(err, record) {
                console.log('put(): ' + record);
                dataset.synchronize({
                    sessionToken: sessionToken,
                    onSuccess: function(dataset, newRecords) {
                        console.log('synchronize() onSuccess, length: ' + newRecords.length);
                    }
                });
            });
        });
    });
}

我已在html中添加了AWS SDK:

<script src='/aws-sdk.min.js'></script>
<script src='/amazon-cognito.min.js'></script>

0 个答案:

没有答案