0.0.1 • Published 9 months ago

passport-cognito-oidc v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

passport-cognito-oidc

License: MIT

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