简体   繁体   中英

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. Mostly all example are based on mobile app, not web app. As per documentation i have created an Identity Pool and i am using Google auth provider. After this the AWS has given me following code -

Get AWS Credential-

       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.

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/

Overall, once you login you need set up your credentials with the google token:

 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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