简体   繁体   English

Alexa帐户与Cognito关联

[英]Alexa Account Linking with Cognito

You would think two of Amazon's products would integrate nicely together. 您会认为Amazon的两种产品可以很好地集成在一起。 You'd also think that Amazon would have proper documentation on their services. 您还认为Amazon将提供有关其服务的适当文档。 Both are horribly wrong. 两者都是非常错误的。

I'm using Account Linking with Alexa and using AWS Cognito as my oauth provider. 我正在使用与Alexa的账户链接,并使用AWS Cognito作为我的oauth提供商。 I am able to successfully link my account just fine, and with every subsequent alexa invocation I get an access token returned back to me. 我能够很好地成功链接我的帐户,并且在随后的所有alexa调用中,我都获得了一个返回给我的访问令牌。 Now what? 怎么办?

I need to be able to access other AWS services such as dynamo, lambda, and iot from my alexa lambda function. 我需要能够从我的alexa lambda函数访问其他AWS服务,例如发电机,lambda和iot。 Thought it would be as easy as something like this: 以为它会像这样简单:

var accessToken = event.session.user.accessToken;
var params = {
    IdentityPoolId: "{identity_pool_id}",
    Logins : {
        'cognito-idp.us-east-1.amazonaws.com/{user_pool_id}' : accessToken
    }
};

AWS.config.region = 'us-east-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials(params);
    AWS.config.credentials.get(function(err) {
    if (err) {
        console.log(err);
    } else {
        console.log('success');
        console.log("Cognito Identity Id: " + AWS.config.credentials.identityId);
    }
});

But of course it's not that simple. 但是当然不是那么简单。 Can anyone help me out? 谁能帮我吗?

You need to assign appropriate "Policies" for the created "Role" under IAM. 您需要为IAM下创建的“角色”分配适当的“策略”。 All of the AWS services works on policy based access permissions and these must be explicitly attached with the IAM role for that role to be able to access/run the underlying service on the behalf of that user role. 所有AWS服务都基于基于策略的访问权限,并且必须将这些服务与IAM角色明确关联,以使该角色能够代表该用户角色访问/运行基础服务。

In summary you need to assign policies from IAM related to "IOT", "DynamoDB", "Lambda", etc. 总之,您需要从IAM分配与“ IOT”,“ DynamoDB”,“ Lambda”等相关的策略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM