GithubHelp home page GithubHelp logo

obscure-web / passport-oauth2-cognito Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 4.0 5 KB

Passport strategy for authenticating and fetching profile data from AWS Cognito User pools using OAuth2 and the Amazon SDK

License: MIT License

JavaScript 100.00%

passport-oauth2-cognito's Introduction

passport-oauth2-cognito

Passport strategy for authenticating and fetching profile data from AWS Cognito User pools using OAuth2 and the Amazon SDK

Install

$ npm install passport-oauth2-cognito

Usage

Configure Strategy

The Cognito OAuth 2.0 authentication strategy authenticates requests using the OAuth 2.0 framework and retrieves user data from AWS Cognito User Pools. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying a consumer key, consumer secret, and callback URL.

const passport = require('passport')
const OAuth2CognitoStrategy = require('passport-oauth2-cognito');

const options = {
  callbackURL: 'https://myapp.com/auth/cognito/callback',
  clientDomain: 'https://myapp.auth.us-west-2.amazoncognito.com',
  clientID: '123-456-789',
  clientSecret: 'shhh-its-a-secret',
  region: 'us-west-2'
};

function verify(accessToken, refreshToken, profile, done) {
  User.findOrCreate(profile, (err, user) => {
    done(err, user);
  });
}

passport.use(new OAuth2CognitoStrategy(options, verify));  
passport.serializeUser((user, done) => done(null, user));
passport.deserializeUser((obj, done) => done(null, obj));

Authenticate Requests

Use passport.authenticate(), specifying the 'oauth2-cognito' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/cognito',
  passport.authenticate('oauth2-cognito')
);
app.get('/auth/cognito/callback',
  passport.authenticate('oauth2-cognito'),
  (req,res) => res.send(req.user)  
);

Cognito configuration

When you create your App Client, you will need to generate an App Client Secret

Your App client settings will need:

Enabled Identity Providers: Cognito User Pool

Callback URL(s): options.callbackURL

Allowed OAuth Flows: Authorization code grant

Allowed OAuth Scopes: [openid, aws.cognito.signin.user.admin, profile]

You must also configure a Domain name for use as options.clientDomain

passport-oauth2-cognito's People

Contributors

obscure-web avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

passport-oauth2-cognito's Issues

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.