Skip to content

kg0r0/passport-cognito-oidc

Repository files navigation

passport-cognito-oidc

Npm package version CI License: MIT

🚧 Note: This library is in beta and is not ready for production 🚧

Passport strategies for authenticating with Amazon Cognito user pool using OpenID Connect.

This is a library for the backend that depends on Express. If you are looking for a frontend library, you may use Amplify Library. Also, if you prefer to use Cognito user pools API for sign-in, the AWS SDK is available.

Usage

import express from 'express';
import passport from 'passport';
import session from 'express-session';
import { Strategy as CognitoOIDCStrategy } from 'passport-cognito-oidc';

const app: express.Express = express()

passport.use(new CognitoOIDCStrategy({
  clientId: '<CLIENT_ID>',
  clientSecret: '<CLIENT_SECRET>',
  region: '<REGION>',
  userPoolId: '<USER_POOL_ID>',
  redirectUri: '<REDIRECT_URI>'
}));

/* ---- express-session ----*/
app.use(session({
  name: 'YOUR-SESSION-NAME',
  secret: 'YOUR-SECRET',
  resave: true,
  saveUninitialized: true
}));

app.get('/',
  passport.authenticate('cognito', {}),
  (req: express.Request, res: express.Response) => {
    res.send('OK');
  }
);

Contributing

Thanks for your feedback and contribution to this repo! Please feel free to open issues and send pull-requests.

License

MIT

About

Passport strategies for authenticating with Amazon Cognito user pool using OpenID Connect.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published