Installations
npm install passport-openidconnect
Score
82.4
Supply Chain
98.6
Quality
76.3
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
>= 0.6.0
Typescript Support
No
Node Version
20.5.1
NPM Version
9.8.0
Statistics
195 Stars
340 Commits
179 Forks
15 Watching
6 Branches
13 Contributors
Updated on 25 Nov 2024
Bundle Size
24.07 kB
Minified
7.86 kB
Minified + Gzipped
Languages
JavaScript (99.79%)
Makefile (0.21%)
Total Downloads
Cumulative downloads
Total Downloads
5,935,777
Last day
-28.2%
6,505
Compared to previous day
Last week
0.2%
46,480
Compared to previous week
Last month
8.9%
185,707
Compared to previous month
Last year
32%
1,952,820
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Dev Dependencies
7
passport-openidconnect
Passport strategy for authenticating with OpenID Connect.
This module lets you authenticate using OpenID Connect in your Node.js applications. By plugging into Passport, OpenID Connect-based sign in can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
:heart: Sponsors
Install
1$ npm install passport-openidconnect
Usage
Configure Strategy
The OpenID Connect authentication strategy authenticates users using their account at an OpenID Provider (OP). The strategy needs to be configured with the provider's endpoints, as well as a client ID and secret that has been issued by the provider to the app. Consult the provider's documentation for the locations of these endpoints and instructions on how to register a client.
The strategy takes a verify
function as an argument, which accepts issuer
and profile
as arguments. issuer
is set to an identifier for the OP.
profile
contains the user's profile information
stored in their account at the OP. When authenticating a user, this strategy
uses the OpenID Connect protocol to obtain this information via a sequence of
redirects and back-channel HTTP requests to the OP.
The verify
function is responsible for determining the user to which the
account at the OP belongs. In cases where the account is logging in for the
first time, a new user record is typically created automatically. On subsequent
logins, the existing user record will be found via its relation to the OP
account.
Because the verify
function is supplied by the application, the app is free to
use any database of its choosing. The example below illustrates usage of a SQL
database.
1var OpenIDConnectStrategy = require('passport-openidconnect');
2
3passport.use(new OpenIDConnectStrategy({
4 issuer: 'https://server.example.com',
5 authorizationURL: 'https://server.example.com/authorize',
6 tokenURL: 'https://server.example.com/token',
7 userInfoURL: 'https://server.example.com/userinfo',
8 clientID: process.env['CLIENT_ID'],
9 clientSecret: process.env['CLIENT_SECRET'],
10 callbackURL: 'https://client.example.org/cb'
11 },
12 function verify(issuer, profile, cb) {
13 db.get('SELECT * FROM federated_credentials WHERE provider = ? AND subject = ?', [
14 issuer,
15 profile.id
16 ], function(err, cred) {
17 if (err) { return cb(err); }
18
19 if (!cred) {
20 // The account at the OpenID Provider (OP) has not logged in to this app
21 // before. Create a new user account and associate it with the account
22 // at the OP.
23 db.run('INSERT INTO users (name) VALUES (?)', [
24 profile.displayName
25 ], function(err) {
26 if (err) { return cb(err); }
27
28 var id = this.lastID;
29 db.run('INSERT INTO federated_credentials (user_id, provider, subject) VALUES (?, ?, ?)', [
30 id,
31 issuer,
32 profile.id
33 ], function(err) {
34 if (err) { return cb(err); }
35 var user = {
36 id: id,
37 name: profile.displayName
38 };
39 return cb(null, user);
40 });
41 });
42 } else {
43 // The account at the OpenID Provider (OP) has previously logged in to
44 // the app. Get the user account associated with the account at the OP
45 // and log the user in.
46 db.get('SELECT * FROM users WHERE id = ?', [ cred.user_id ], function(err, row) {
47 if (err) { return cb(err); }
48 if (!row) { return cb(null, false); }
49 return cb(null, row);
50 });
51 }
52 });
53 }
54));
Define Routes
Two routes are needed in order to allow users to log in with their account at an OP. The first route redirects the user to the OP, where they will authenticate:
1app.get('/login', passport.authenticate('openidconnect'));
The second route processes the authentication response and logs the user in, when the OP redirects the user back to the app:
1app.get('/cb', 2 passport.authenticate('openidconnect', { failureRedirect: '/login', failureMessage: true }), 3 function(req, res) { 4 res.redirect('/'); 5 });
Examples
-
Illustrates how to use the OpenID Connect strategy within an Express application.
-
Illustrates how to use the OpenID Connect strategy to integrate with Auth0 in an Express application. For developers new to Passport and getting started, a tutorial is available.
License
Copyright (c) 2011-2022 Jared Hanson <https://www.jaredhanson.me/>
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
8 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq
- Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/jaredhanson/passport-openidconnect/node.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/jaredhanson/passport-openidconnect/node.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/node.yml:42
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.7
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to passport-openidconnect
@types/passport-openidconnect
TypeScript definitions for passport-openidconnect
@govtechsg/passport-openidconnect
OpenID Connect authentication strategy for Passport.
deskfy-passport-openidconnect
OpenID Connect authentication multi strategy for Passport.
passport-openidconnect-keycloak-idp
OpenID Connect authentication strategy for Passport.