Giter Site home page Giter Site logo

cognitodevauthids's Introduction

cognitoDevAuthIds

Example how to implement the Cognito Developer Authenticated Identity Flow

You should use the Developer Authenticated flow when:

  1. You plan to use your own data store to maintain your user database
  2. You want integrate with Cognito so you can vend AWS Credentials for your users

Running the example

This is setup as a SAM project that you can execute with the following command:

sam local invoke authFn -e "event.json"

Steps

alt text

  1. Your users will authenticate against your existing user directory. Your application will handle this.
  2. When the user successfully authenticates, your application will invoke the Cognito API: getOpenIdTokenForDeveloperIdentity . This API will vend an OIDC (JWT format) token that you can exchange for temporary AWS credentials

You will need to pass it parameters in this format:

  var params = {
    IdentityPoolId: '[region]:[id pool GUID]', /* required */
    Logins: { /* required */
      '[unique identifier for your app]': '[unique username]',
    }
  };

This call will return an IdentityId and Token which you will pass into the call to exchange for AWS credentials.

  1. Exchange the token for AWS credentials using getCredentialsForIdentity. Cognito will assign the user a role based on the rules you have configured in your Identity Pool.

You will need to pass it credentials in this format:

  var params = {
    IdentityId: [IdentityId], /* required */
    Logins: {
      'cognito-identity.amazonaws.com': [Token]
    }
  };

This call will return temporary credentials in this format:

{
   IdentityId: '',
   Credentials: {
   	AccessKeyId: '',
   	SecretKey: '',
   	SessionToken: '',
   	Expiration: 
   }
}

Notes

  • You must invoke the getOpenIdTokenForDeveloperIdentity API using AWS Developer credentials with permissions: cognito-identity:GetOpenIdTokenForDeveloperIdentity
  • getCredentialsForIdentity is a public API. You do not need any credentials to call this API
  • See AWS Docs for details

cognitodevauthids's People

Contributors

georgmao avatar

Stargazers

Lalit avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.