Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

passport-auth0

auth0249.2kMIT1.4.4TypeScript support: definitely-typed

Auth0 platform authentication strategy for Passport.js

readme

Auth0 authentication strategy for Passport.js

The Auth0 authentication strategy for Passport.js, an authentication middleware for Node.js that can be unobtrusively dropped into any Express-based web application.

Release npm License CircleCI

:books: Documentation - :rocket: Getting Started - :speech_balloon: Feedback

Documentation

  • Docs site - explore our docs site and learn more about Auth0.

Getting started

:information_source: Maintenance Advisory: With the release of https://github.com/auth0/express-openid-connect, we will no longer be adding new features to this library, however we will continue to maintain this library and fix issues. You can read more about the release of our new library at https://auth0.com/blog/auth0-s-express-openid-connect-sdk/

Installation

The Auth0 Passport strategy is installed with npm.

npm install passport-auth0

Customization

State parameter

The Auth0 Passport strategy enforces the use of the state parameter in OAuth 2.0 authorization requests and requires session support in Express to be enabled.

If you require the state parameter to be omitted (which is not recommended), you can suppress it when calling the Auth0 Passport strategy constructor:

const Auth0Strategy = require('passport-auth0');
const strategy = new Auth0Strategy({
     // ...
     state: false
  },
  function(accessToken, refreshToken, extraParams, profile, done) {
    // ...
  }
);

More on state handling here.

Scopes

If you want to change the scope of the ID token provided, add a scope property to the authenticate configuration passed when defining the route. These must be OIDC standard scopes. If you need data outside of the standard scopes, you can add custom claims to the token.

app.get(
    '/login',
    passport.authenticate('auth0', {scope: 'openid email profile'}), 
    function (req, res) {
        res.redirect('/');
    }
);

Force a Specific IdP

If you want to force a specific identity provider you can use:

app.get(
    '/login/google',
    passport.authenticate('auth0', {connection: 'google-oauth2'}), 
    function (req, res) {
        res.redirect('/');
    }
);

If you force an identity provider you can also request custom scope from that identity provider:

app.get(
    '/login/google', 
    passport.authenticate('auth0', {
        connection: 'google-oauth2',
        connection_scope: 'https://www.googleapis.com/auth/analytics, https://www.googleapis.com/auth/contacts.readonly'
    }), 
    function (req, res) {
        res.redirect('/');
    }
);

Getting Access Tokens

If you want to specify an audience for the returned access_token you can:

app.get(
    '/login',
    passport.authenticate('auth0', {audience: 'urn:my-api'}), 
    function (req, res) {
      res.redirect('/');
    }
);

Silent Authentication

If you want to check authentication without showing a prompt:

app.get(
    '/login',
    passport.authenticate('auth0', {prompt: 'none'}), 
    function (req, res) {
        res.redirect('/');
    }
);

Feedback

Contributing

We appreciate feedback and contribution to this repo! Before you get started, please see the following:

Raise an issue

To provide feedback or report a bug, please raise an issue on our issue tracker.

Vulnerability Reporting

Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.


<picture> <source media="(prefers-color-scheme: light)" srcset="https://cdn.auth0.com/website/sdks/logos/auth0_light_mode.png" width="150"> <source media="(prefers-color-scheme: dark)" srcset="https://cdn.auth0.com/website/sdks/logos/auth0_dark_mode.png" width="150"> Auth0 Logo </picture>

Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?

This project is licensed under the MIT license. See the LICENSE file for more info.

changelog

Change Log

v1.4.4 (2023-10-30)

Full Changelog

Security

v1.4.3 (2022-08-16)

Full Changelog

Fixed

v1.4.2 (2022-01-19)

Full Changelog

Fixed Upgrade axios from 0.21.4 to 0.22.0 #149 (snyk-bot)

v1.4.1 (2021-10-13)

Full Changelog

Changed Replace request with axios #144 (frederikprijck)

v1.4.0 (2020-10-22)

Full Changelog

Added Adding support for extra params to authorizeParams #131 (alexbjorlig)

Security Bump lodash from 4.17.15 to 4.17.20 #129

Fixed Fix to not override option values with defaults. #127 (kierans)

v1.3.3 (2020-06-05)

Full Changelog

Closed issues

  • Having a session is now required#107

Fixed

Security

v1.3.2 (2020-02-03)

Full Changelog

Closed issues

  • 1.2.1 -> 1.3.1 upgrade causes "Cannot read property 'scope' of undefined" #107
  • TypeError: Cannot read property 'authParams' of undefined #106
  • Cannot read property 'split' of undefined in Profile.js with GSuite login #105

Fixed

v1.3.1 (2019-12-06)

Full Changelog

Closed issues

  • the userProfile does not have 'provider' field correctly populated. #102
  • Social login breaks when account name contains utf-8 characters. #100
  • Strategy does not work on Restify #96

Fixed

  • Parses provider from user_id if identities is not provided. #103 (kertof)
  • Fix decoding jwt when encoded payload contains utf8 characters #101 (abelptvts)

v1.3.0 (2019-11-19)

Full Changelog

Added

Security

v1.2.1 (2019-08-12)

Full Changelog

Closed issues

  • Strategy constructor mutates options argument #91
  • Infinite redirect loop, "Invalid authorization request state." #89
  • could I use cookie-session instead of express-session? #87

Fixed

  • Fix strategy constructor to not mutate options argument #92 (naptowncode)

v1.2.0 (2019-07-31)

Full Changelog

Closed issues

  • Not obvious how to style lock on redirect #74
  • Auth0 state parameter not always passed through #73
  • Allow for different grant types #72
  • Use native Object.assign instead of xtend #67
  • state parameter default to true #65
  • Custom Claims? #64
  • Auth0Strategy vs OAuth2Strategy #61
  • logout problems #59
  • What is the point of this line? #56
  • Custom User Store vs Auth0 Database #54
  • Setting a proxy #50
  • Document how to access the "state" parameter #40
  • Incompatible with Lock for Web's responseMode option #39
  • Return to same page after login? #38
  • refreshToken is always null #36
  • JWT Token #30
  • Specify JWT scope #29
  • Rule Errors do not propagate #28

Added

Changed

Security

  • Update mocha package to address security vulnerabilities #82 (dan-auth0)
  • [Snyk] Fix for 5 vulnerable dependencies #77 (snyk-bot)