How to use the passport-oauth2-refresh.requestNewAccessToken function in passport-oauth2-refresh

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 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
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 Makeshift / eve-goons-waitlist / models / user.js View on Github external
db.findOne({characterID: characterID}, function(err, doc){
			refresh.requestNewAccessToken('provider', doc.refreshToken, function(error, accessToken, newRefreshToken){
				if(error){
					log.error("user.getRefreshToken - requestNewAccessToken: ", {pilot: characterID, error});
					tokenCallback(null);
					return;
				}

				db.updateOne({ 'characterID': characterID }, { $set: { refreshToken: newRefreshToken } }, function (err, result) {
					if (err) log.error("user.getRefreshToken: Error for updateOne", { err, 'characterID': characterID });
					tokenCallback(accessToken);
					return;
				})
			});
		})
	}

passport-oauth2-refresh

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

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis