Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
@nestjs/passport
Advanced tools
Nest - modern, fast, powerful node.js web framework (@passport)
@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.
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 549,007 weekly downloads. As such, @nestjs/passport popularity was classified as popular.
We found that @nestjs/passport demonstrated a not healthy version release cadence and project activity because the last version was released 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
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.