How to use passport-oauth2-refresh - 10 common examples

To help you get started, we’ve selected a few passport-oauth2-refresh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github freeCodeCamp / meeting-for-good / server / api / ggcalendar / ggcalendar.controller.js View on Github external
const refreshToken = (curUser, req, res, origin) => {
  refresh.requestNewAccessToken('google', curUser.refreshToken,
    (err, newAccessToken) => {
      if (err) {
        console.error('ERROR at refreshToken requestNewAccessToken', err);
        return res.status(500).send('ERROR at refreshToken requestNewAccessToken');
      }
      curUser.accessToken = newAccessToken;
      curUser.save((err) => {
        if (err) {
          console.error('ERROR at save curUserrequestNewAccessToken', err);
          return res.status(500).send('ERROR at save curUserrequestNewAccessToken');
        }
          /* eslint-disable */
        switch (origin) {
          case 'getCalList':
            return getCalList(req, res, curUser, true);
          case 'getCalEventsList':
github tmilar / meli-manager / config / meli-auth.js View on Github external
/**
 * Setup mercadolibre passport Strategy.
 *
 * @type {Strategy}
 */
const mercadoLibreStrategy = new MercadoLibreStrategy({
  clientID: clientId,
  clientSecret,
  callbackURL: '/auth/mercadolibre/callback'
},
authorizedCb
)
passport.use(mercadoLibreStrategy)

refresh.use(mercadoLibreStrategy)

// Add promise support to refresh
refresh.requestNewAccessToken = Promise.promisify(refresh.requestNewAccessToken)

module.exports = meliAuth
github gadael / gadael / schema / User.js View on Github external
return new Promise((resolve, reject) => {

            oauthrefresh.use(getStrategy(params.app.config));

            oauthrefresh.requestNewAccessToken('google', user.google.refreshToken, function(err, accessToken, refreshToken) {

                if (err) {
                    return reject(err);
                }

                if (!accessToken) {
                    return reject(new Error('refresh google access token give no result'));
                }

                user.google.accessToken = accessToken;
                if (refreshToken) {
                    // should be the same of the initial refresh token
                    user.google.refreshToken = refreshToken;
                }
github gadael / gadael / schema / User.js View on Github external
return new Promise((resolve, reject) => {

            oauthrefresh.use(getStrategy(params.app.config));

            oauthrefresh.requestNewAccessToken('google', user.google.refreshToken, function(err, accessToken, refreshToken) {

                if (err) {
                    return reject(err);
                }

                if (!accessToken) {
                    return reject(new Error('refresh google access token give no result'));
                }

                user.google.accessToken = accessToken;
                if (refreshToken) {
                    // should be the same of the initial refresh token
                    user.google.refreshToken = refreshToken;
                }
                resolve(user.save());
            });
github DefinitelyTyped / DefinitelyTyped / types / passport-oauth2-refresh / passport-oauth2-refresh-tests.ts View on Github external
const strategyOptions1: StrategyOptions = {
    authorizationURL: 'http://www.example.com/auth',
    callbackURL: 'http://www.example.com/callback',
    clientID: 'dummy',
    clientSecret: 'secret',
    tokenURL: 'http://www.example.com/token'
};

function verifyFunction1(_accessToken: string, _refreshToken: string, _profile: any, verifyCallback: VerifyCallback) {
    verifyCallback(new Error('unimplemented'));
}

const strategy1: OAuth2Strategy = new OAuth2Strategy(strategyOptions1, verifyFunction1);

use('strategy1', strategy1);

requestNewAccessToken('strategy1', 'exampleRefreshToken', (err, accessToken, refreshToken, results) => {});
requestNewAccessToken('strategy1', 'exampleRefreshToken', {}, (err, accessToken, refreshToken, results) => {});
github DefinitelyTyped / DefinitelyTyped / types / passport-oauth2-refresh / passport-oauth2-refresh-tests.ts View on Github external
authorizationURL: 'http://www.example.com/auth',
    callbackURL: 'http://www.example.com/callback',
    clientID: 'dummy',
    clientSecret: 'secret',
    tokenURL: 'http://www.example.com/token'
};

function verifyFunction1(_accessToken: string, _refreshToken: string, _profile: any, verifyCallback: VerifyCallback) {
    verifyCallback(new Error('unimplemented'));
}

const strategy1: OAuth2Strategy = new OAuth2Strategy(strategyOptions1, verifyFunction1);

use('strategy1', strategy1);

requestNewAccessToken('strategy1', 'exampleRefreshToken', (err, accessToken, refreshToken, results) => {});
requestNewAccessToken('strategy1', 'exampleRefreshToken', {}, (err, accessToken, refreshToken, results) => {});
github michaelwilcox / headfon.es / server / src / services / jwt / strategy.ts View on Github external
async (user, next) => {
  try {
    const userLookup = new User(user);
    const savedUser = await userLookup.getUser();

    const minutesUntilExpiration = getMinutesUntilExpiration(savedUser.timeExpires);

    if (minutesUntilExpiration < 0) {
      refresh.requestNewAccessToken('spotify', savedUser.refreshToken, async (err, accessToken, refreshToken) => {
        if (err) {
          console.error(err);
        }
    
        try {
          const timeExpires = getTimeExpires();
          const { id } = savedUser;
          const userForSave = new User({ id, accessToken, timeExpires });
          const updatedUser = await userForSave.updateAccessToken();
          
          next(null, updatedUser);
        } catch (e) {
          console.error(e);
        }
      });
    } else {
github freeCodeCamp / meeting-for-good / server / auth / google / passport.js View on Github external
export const setup = (User, config) => {
  passport.use(strategy(User, config));
  refresh.use(strategy(User, config));
};
github Makeshift / eve-goons-waitlist / index.js View on Github external
done(success);
				}
			});
		});

	passport.serializeUser(function (user, done) {
		done(null, user);
	});

	passport.deserializeUser(function (user, done) {
		done(null, user);
	});

	//Extend some stuff
	passport.use('provider', oauthStrategy);
	refresh.use('provider', oauthStrategy);
	app.use(session({
		store: new mongoStore({ db: database.db }),
		secret: setup.data.sessionSecret,
		cookie: { maxAge: 604800 * 1000 }, //Week long cookies for week long incursions!
    resave: true,
    saveUninitialized: true
	}))

	app.use(cookieParser());
	app.use(session({ secret: setup.data.sessionSecret }));
	app.use(flash({ locals: 'flash' }));
	app.use(passport.initialize());
	app.use(passport.session());
	app.use(bodyParser.urlencoded({ extended: true }));
	app.use('/includes', express.static('public/includes'));
	app.use(users.updateUserSession); //Force the session to update from DB on every page load because sessions are not the source of truth here!
github amitava82 / radiole / server / lib / core / passport.js View on Github external
e => cb(e)
                )
            }
        });
    }

    var spotify = new SpotifyStrategy({
            clientID: config.get('auth.spotify.clientId'),
            clientSecret: config.get('auth.spotify.clientSecret'),
            callbackURL: callbackUrl('spotify')
        }, _callback
    );

    passport.use(spotify);

    refresh.use(spotify);

    passport.serializeUser(function(user, cb) {
        cb(null, user._id);
    });

    passport.deserializeUser(function(id, cb) {
        var User = deps.models.User;
        User.findById(id).select('+access_token').lean().exec(cb);
    });

    return passport;
};

passport-oauth2-refresh

A passport.js add-on to provide automatic OAuth 2.0 token refreshing.

MIT
Latest version published 1 year ago

Package Health Score

57 / 100
Full package analysis