Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

passport-oauth2

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-oauth2

OAuth 2.0 authentication strategy for Passport.

  • 1.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
406K
decreased by-42.84%
Maintainers
1
Weekly downloads
 
Created

What is passport-oauth2?

The `passport-oauth2` npm package is a strategy for the Passport authentication middleware that allows you to authenticate using OAuth 2.0. It is designed to be flexible and can be used with any OAuth 2.0 provider, making it a versatile tool for integrating third-party authentication into your Node.js applications.

What are passport-oauth2's main functionalities?

OAuth 2.0 Authentication

This feature allows you to set up OAuth 2.0 authentication with a specified provider. The code sample demonstrates how to configure the OAuth2Strategy with the necessary endpoints and client credentials, and how to handle the authentication callback.

const passport = require('passport');
const OAuth2Strategy = require('passport-oauth2').Strategy;

passport.use(new OAuth2Strategy({
    authorizationURL: 'https://example.com/oauth2/authorize',
    tokenURL: 'https://example.com/oauth2/token',
    clientID: 'YOUR_CLIENT_ID',
    clientSecret: 'YOUR_CLIENT_SECRET',
    callbackURL: 'https://www.example.net/auth/example/callback'
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ exampleId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

Custom Authorization Parameters

This feature allows you to add custom headers or parameters to the authorization request. The code sample shows how to include custom headers in the OAuth2Strategy configuration.

passport.use(new OAuth2Strategy({
    authorizationURL: 'https://example.com/oauth2/authorize',
    tokenURL: 'https://example.com/oauth2/token',
    clientID: 'YOUR_CLIENT_ID',
    clientSecret: 'YOUR_CLIENT_SECRET',
    callbackURL: 'https://www.example.net/auth/example/callback',
    customHeaders: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN' }
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ exampleId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

Token Revocation

This feature allows you to revoke an OAuth 2.0 token. The code sample demonstrates how to send a POST request to the token revocation endpoint with the token to be revoked.

const request = require('request');

function revokeToken(token, done) {
  const options = {
    url: 'https://example.com/oauth2/revoke',
    form: { token: token }
  };
  request.post(options, function(err, response, body) {
    if (err) { return done(err); }
    done(null, body);
  });
}

Other packages similar to passport-oauth2

Keywords

FAQs

Package last updated on 20 Dec 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc