[英]How to use Amazon Cognito with S3 for web application
I have gone through official docs and various AWS blog, to create a web application using Cognito. 我浏览了官方文档和各种AWS博客,使用Cognito创建了一个Web应用程序。 Mostly all example are based on mobile app, not web app. 大多数情况下,所有示例都基于移动应用程序,而不是基于Web应用程序。 As per documentation i have created an Identity Pool and i am using Google auth provider. 根据文档,我已经创建了一个身份池,并且正在使用Google身份验证提供程序。 After this the AWS has given me following code - 之后,AWS给了我以下代码-
Get AWS Credential- 获取AWS凭证-
AWS.config.region = 'ap-northeast-1'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'IDENTITY_POOL_ID',
});
Store User Data - 存储用户数据-
AWS.config.credentials.get(function(){
var syncClient = new AWS.CognitoSyncManager();
syncClient.openOrCreateDataset('myDataset', function(err, dataset) {
dataset.put('myKey', 'myValue', function(err, record){
dataset.synchronize({
onSuccess: function(data, newRecords) {
// Your handler code here
}
});
});
});
});
From here i am clue less how to proceed. 从这里我不太了解如何进行。 In my html page i have a login button, on click to the button which function i have to call, which basically invoke the google authenticator. 在我的html页面中,我有一个登录按钮,单击该按钮我必须调用的函数,该函数基本上会调用Google身份验证器。
Thanks. 谢谢。
These docs may be helpful for you with passing your google token to Amazon Cognito (make sure you select javascript as your language): http://docs.aws.amazon.com/cognito/devguide/identity/external-providers/google/ 这些文档可能对您将Google令牌传递给Amazon Cognito(确保您选择javascript作为语言)有帮助: http : //docs.aws.amazon.com/cognito/devguide/identity/external-providers/google/
Overall, once you login you need set up your credentials with the google token: 总体而言,登录后,您需要使用Google令牌设置凭据:
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'IDENTITY_POOL_ID',
Logins: {
'accounts.google.com': authResult['id_token']
}
});
Once your credentials are set up, you should be able to call other services (that you give your users permissions to call). 设置凭据后,您应该能够调用其他服务(您已授予用户调用权限)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.