Gathering detailed insights and metrics for passport-oauth2-refresh
Gathering detailed insights and metrics for passport-oauth2-refresh
Gathering detailed insights and metrics for passport-oauth2-refresh
Gathering detailed insights and metrics for passport-oauth2-refresh
npm install passport-oauth2-refresh
Typescript
Module System
Min. Node Version
Node Version
NPM Version
93.7
Supply Chain
100
Quality
76
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
4,054,496
Last Day
461
Last Week
10,319
Last Month
70,741
Last Year
943,904
190 Stars
60 Commits
16 Forks
3 Watching
8 Branches
5 Contributors
Minified
Minified + Gzipped
Latest Version
2.2.0
Package Id
passport-oauth2-refresh@2.2.0
Unpacked Size
25.43 kB
Size
7.43 kB
File Count
10
NPM Version
8.15.0
Node Version
16.17.0
Publised On
15 Apr 2023
Cumulative downloads
Total Downloads
Last day
-86.4%
461
Compared to previous day
Last week
-40.6%
10,319
Compared to previous week
Last month
-9.6%
70,741
Compared to previous month
Last year
16.1%
943,904
Compared to previous year
An add-on to the Passport authentication library to provide a simple way to refresh your OAuth 2.0 access tokens.
npm install passport-oauth2-refresh
When setting up your passport strategies, add a call to refresh.use()
after passport.use()
.
An example, using the Facebook strategy:
1const passport = require('passport'); 2const refresh = require('passport-oauth2-refresh'); 3const FacebookStrategy = require('passport-facebook').Strategy; 4 5const strategy = new FacebookStrategy({ 6 clientID: FACEBOOK_APP_ID, 7 clientSecret: FACEBOOK_APP_SECRET, 8 callbackURL: "http://www.example.com/auth/facebook/callback" 9}, 10function(accessToken, refreshToken, profile, done) { 11 // Make sure you store the refreshToken somewhere! 12 User.findOrCreate(..., function(err, user) { 13 if (err) { return done(err); } 14 done(null, user); 15 }); 16}); 17 18passport.use(strategy); 19refresh.use(strategy);
When you need to refresh the access token, call requestNewAccessToken()
:
1const refresh = require('passport-oauth2-refresh'); 2refresh.requestNewAccessToken( 3 'facebook', 4 'some_refresh_token', 5 function (err, accessToken, refreshToken) { 6 // You have a new access token, store it in the user object, 7 // or use it to make a new request. 8 // `refreshToken` may or may not exist, depending on the strategy you are using. 9 // You probably don't need it anyway, as according to the OAuth 2.0 spec, 10 // it should be the same as the initial refresh token. 11 }, 12);
Instead of using the default strategy.name
, you can setup passport-oauth2-refresh
to use an specific name instead.
1// Setup 2passport.use('gmail', googleStrategy); 3 4// To refresh 5refresh.requestNewAccessToken('gmail', 'some_refresh_token', done);
This can be useful if you'd like to reuse strategy objects but under a different name.
Most passport strategies that use OAuth 2.0 should work without any additional configuration. Some strategies, however require custom OAuth configuration, or do not expose an oauth2 adapter for internal use. In these cases, a callback can be specified by calling the use
function with an extra options
parameter:
1const { OAuth2 } = require('oauth'); 2 3refresh.use(strategy, { 4 setRefreshOAuth2() { 5 return new OAuth2(/* custom oauth config */); 6 }, 7});
The setRefreshOAuth2
callback should return an instance of the node-oauth OAuth2 class.
The callback is called with two named parameters, which can be used to further customise the OAuth2 adapter:
1refresh.use(strategy, {
2 setRefreshOAuth2({ strategyOAuth2, refreshOAuth2 }) {
3 // These named parameters are set for most strategies.
4 // The `refreshOAuth2` instance is a clone of the one supplied by the strategy, inheriting most of its config.
5 // Customise it here and return if necessary.
6 // For example, to set a proxy:
7 refreshOAuth2.setAgent(new HttpsProxyAgent(agentUrl));
8 return refreshOAuth2;
9 },
10});
Some endpoints require additional parameters to be sent when requesting a new access token. To send these parameters, specify the parameters when calling requestNewAccessToken
as follows:
1const extraParams = { some: 'extra_param' }; 2refresh.requestNewAccessToken('gmail', 'some_refresh_token', extraParams, done);
Projects that need multiple instances of Passport can construct them using the Passport
constructor available on the passport
module. Similarly, this module provides
an AuthTokenRefresh
constructor that can be used instead of the single instance provided
by default.
1const { Passport } = require('passport'); 2const { AuthTokenRefresh } = require('passport-oauth2-refresh'); 3 4const passport = new Passport(); 5const refresh = new AuthTokenRefresh(); 6 7// Additional, distinct instances of these modules can also be created
Passport is a library which doesn't deal in implementation-specific details. From the author:
Passport is a library for authenticating requests, and only that. It is not going to get involved in anything that is specific to OAuth, or any other authorization protocol.
Fair enough. Hence, this add-on was born as a way to help deal with refreshing OAuth 2.0 tokens.
It is particularly useful when dealing with Google's OAuth 2.0 implementation, which expires access tokens after 1 hour.
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 2/29 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
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
10 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-23
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 More