Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@nestjs/passport
Advanced tools
@nestjs/passport is a NestJS module that provides integration with the Passport authentication middleware. It allows developers to implement various authentication strategies in a NestJS application, such as local, JWT, OAuth, and more.
Local Authentication
This feature allows you to implement local authentication using a username and password. The code sample demonstrates how to set up a local strategy with Passport.
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
passport.use(new LocalStrategy(
function(username, password, done) {
User.findOne({ username: username }, function (err, user) {
if (err) { return done(err); }
if (!user) { return done(null, false); }
if (!user.verifyPassword(password)) { return done(null, false); }
return done(null, user);
});
}
));
JWT Authentication
This feature allows you to implement JWT authentication. The code sample demonstrates how to set up a JWT strategy with Passport.
const passport = require('passport');
const { Strategy: JwtStrategy, ExtractJwt } = require('passport-jwt');
const opts = {
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: 'your_jwt_secret'
};
passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
User.findById(jwt_payload.sub, function(err, user) {
if (err) {
return done(err, false);
}
if (user) {
return done(null, user);
} else {
return done(null, false);
}
});
}));
OAuth Authentication
This feature allows you to implement OAuth authentication using providers like Google. The code sample demonstrates how to set up a Google OAuth strategy with Passport.
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
passport.use(new GoogleStrategy({
clientID: 'YOUR_GOOGLE_CLIENT_ID',
clientSecret: 'YOUR_GOOGLE_CLIENT_SECRET',
callbackURL: 'http://www.example.com/auth/google/callback'
},
function(token, tokenSecret, profile, done) {
User.findOrCreate({ googleId: profile.id }, function (err, user) {
return done(err, user);
});
}));
Passport is a popular authentication middleware for Node.js. It is highly flexible and supports a wide range of authentication strategies. While @nestjs/passport is specifically designed for NestJS, Passport can be used with any Node.js application.
Express-session is a middleware for managing sessions in Express applications. While it does not provide authentication strategies like @nestjs/passport, it is often used in conjunction with Passport to manage user sessions.
Jsonwebtoken is a library for generating and verifying JSON Web Tokens (JWT). It is often used in combination with Passport's JWT strategy to handle token-based authentication. Unlike @nestjs/passport, it does not provide a complete authentication framework but focuses on JWT handling.
A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.
This is a Passport utilities module for Nest.
$ npm i --save @nestjs/passport passport
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Nest is MIT licensed.
FAQs
Nest - modern, fast, powerful node.js web framework (@passport)
The npm package @nestjs/passport receives a total of 664,443 weekly downloads. As such, @nestjs/passport popularity was classified as popular.
We found that @nestjs/passport demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.