Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
cognito-passport-oauth2
Advanced tools
A passport strategy to authenticate against an AWS Cognito User Pool OAuth 2.0 provider and get user profile, access token and ID token. This supports providing cognito specific additional auth parameters. This is subclass of passport-oauth2 strategy.
Passport Cognito OAuth2 strategy for AWS Cognito User Pools. This supports providing congnito specific additional auth parameters. This is subclass of passport-oauth2 strategy.
$ npm i cognito-passport-oauth2
The strategy takes a verify
function, auth options
, and optional additional auth params
.
Find simple working example here.
const passport = require('passport'),
CognitoOAuth2Strategy = require('cognito-passport-oauth2');
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(async function (user, done) {
done(null, user);
});
const options = {
callbackURL: 'http://localhost:4001/auth/callbacks', //Your callback url
clientDomain: 'https://yourdomain.auth.eu-west-1.amazoncognito.com', //Your cognito user pool domain
clientID: 'your cognito app client id',
clientSecret: 'your cognito app client secret',
region: 'eu-west-1', //your region
passReqToCallback: true
};
//Indicates the provider that the end user should authenticate with.
//You can as well provide other custom auth params
const customOptions = { identity_provider: 'your idp name' };
async function verify(req, accessToken, refreshToken, { id_token }, profile, done) //if you need id_token, use this signature
or
async function verify(req, accessToken, refreshToken, profile, done) {
//Your additional user logic
let sessionData = {
username: profile.username
//additional props
}
return done(null, sessionData);
};
passport.use('cognito', new CognitoOAuth2Strategy(options, verify, customOptions));
or
passport.use('cognito', new CognitoOAuth2Strategy(options, verify)); //go to default cognito login page and let user choose the idp
Use passport.authenticate()
, specifying the 'cognito'
strategy
app.get('/auth/login', passport.authenticate('cognito'));
or
app.get('/auth/login', passport.authenticate('cognito', additionalAuthParameters)); //Overwrite customOptions (see above) or provide additional auth params
app.get('/auth/callback', passport.authenticate('cognito', { failureRedirect: '/error', failureFlash: true, successRedirect: '/index' }));
Refer here for more information about configuring cognito app client
FAQs
A passport strategy to authenticate against an AWS Cognito User Pool OAuth 2.0 provider and get user profile, access token and ID token. This supports providing cognito specific additional auth parameters. This is subclass of passport-oauth2 strategy.
The npm package cognito-passport-oauth2 receives a total of 118,176 weekly downloads. As such, cognito-passport-oauth2 popularity was classified as popular.
We found that cognito-passport-oauth2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.