Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
@types/passport-local
Advanced tools
TypeScript definitions for passport-local
@types/passport-local provides TypeScript type definitions for the passport-local strategy, which is a Passport.js strategy for authenticating with a username and password.
LocalStrategy
This feature allows you to define a local authentication strategy using a username and password. The code sample demonstrates how to set up the LocalStrategy with Passport.js.
const LocalStrategy = require('passport-local').Strategy;
const passport = require('passport');
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, { message: 'Incorrect username.' }); }
if (!user.validPassword(password)) { return done(null, false, { message: 'Incorrect password.' }); }
return done(null, user);
});
}
));
Serialization and Deserialization
This feature allows you to serialize and deserialize user information to maintain authentication state across HTTP requests. The code sample shows how to implement these methods with Passport.js.
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function (err, user) {
done(err, user);
});
});
Middleware Integration
This feature allows you to integrate Passport.js middleware into an Express application. The code sample demonstrates how to set up session management and authentication routes.
const express = require('express');
const passport = require('passport');
const app = express();
app.use(require('express-session')({ secret: 'secret', resave: false, saveUninitialized: false }));
app.use(passport.initialize());
app.use(passport.session());
app.post('/login', passport.authenticate('local', { successRedirect: '/', failureRedirect: '/login' }));
@types/passport provides TypeScript type definitions for the core Passport.js library. It is essential for adding type safety to your Passport.js authentication strategies and middleware.
@types/passport-jwt provides TypeScript type definitions for the passport-jwt strategy, which is used for authenticating with JSON Web Tokens (JWT). It is useful for applications that use token-based authentication instead of session-based.
@types/passport-google-oauth20 provides TypeScript type definitions for the passport-google-oauth20 strategy, which is used for authenticating with Google OAuth 2.0. It is useful for applications that want to allow users to log in using their Google accounts.
npm install --save @types/passport-local
This package contains type definitions for passport-local (https://github.com/jaredhanson/passport-local).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/passport-local.
// Type definitions for passport-local 1.0.0
// Project: https://github.com/jaredhanson/passport-local
// Definitions by: Maxime LUCE <https://github.com/SomaticIT>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="passport"/>
import { Strategy as PassportStrategy } from "passport-strategy";
import express = require("express");
interface IStrategyOptions {
usernameField?: string | undefined;
passwordField?: string | undefined;
session?: boolean | undefined;
passReqToCallback?: false | undefined;
}
interface IStrategyOptionsWithRequest {
usernameField?: string | undefined;
passwordField?: string | undefined;
session?: boolean | undefined;
passReqToCallback: true;
}
interface IVerifyOptions {
message: string;
}
interface VerifyFunctionWithRequest {
(
req: express.Request,
username: string,
password: string,
done: (error: any, user?: any, options?: IVerifyOptions) => void
): void;
}
interface VerifyFunction {
(
username: string,
password: string,
done: (error: any, user?: any, options?: IVerifyOptions) => void
): void;
}
declare class Strategy extends PassportStrategy {
constructor(
options: IStrategyOptionsWithRequest,
verify: VerifyFunctionWithRequest
);
constructor(options: IStrategyOptions, verify: VerifyFunction);
constructor(verify: VerifyFunction);
name: string;
}
These definitions were written by Maxime LUCE.
FAQs
TypeScript definitions for passport-local
The npm package @types/passport-local receives a total of 285,840 weekly downloads. As such, @types/passport-local popularity was classified as popular.
We found that @types/passport-local demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.