How to use the passport-oauth2.InternalOAuthError function in passport-oauth2

To help you get started, we’ve selected a few passport-oauth2 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 fh1ch / passport-gitlab2 / lib / strategy.js View on Github external
self._oauth2.get(self._profileURL, accessToken, function(err, body) {
    let json;

    if (err) {
      return done(new InternalOAuthError('Failed to fetch user profile', err));
    }

    try {
      json = JSON.parse(body);
    } catch (ex) {
      return done(new Error('Failed to parse user profile'));
    }

    const profile = {
      id: String(json.id),
      username: json.username,
      displayName: json.name,
      emails: [{value: json.email}],
      // jshint camelcase: false
      // jscs:disable requireCamelCaseOrUpperCaseIdentifiers
      avatarUrl: json.avatar_url,
github jaredhanson / passport-google-oauth2 / lib / strategy.js View on Github external
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
    var json;
    
    if (err) {
      if (err.data) {
        try {
          json = JSON.parse(err.data);
        } catch (_) {}
      }
      
      if (json && json.error && json.error.message) {
        return done(new GooglePlusAPIError(json.error.message, json.error.code));
      } else if (json && json.error && json.error_description) {
        return done(new UserInfoError(json.error_description, json.error));
      }
      return done(new InternalOAuthError('Failed to fetch user profile', err));
    }
    
    try {
      json = JSON.parse(body);
    } catch (ex) {
      return done(new Error('Failed to parse user profile'));
    }
    
    var profile;
    switch (self._userProfileFormat) {
    case 'openid':
      profile = OpenIDProfile.parse(json);
      break;
    default: // Google Sign-In
      profile = GooglePlusProfile.parse(json);
      break;
github DefinitelyTyped / DefinitelyTyped / types / passport-oauth2 / passport-oauth2-tests.ts View on Github external
callbackURL: 'http://www.example.com/callback',
    clientID: 'dummy',
    clientSecret: 'secret',
    tokenURL: 'http://www.example.com/token',
    passReqToCallback: true
};

const strategy3: PassportStrategy = new OAuth2Strategy(strategyOptions2, verifyFunction3);

const strategy4: Strategy = new Strategy(strategyOptions2, verifyFunction4);

const err1 = new AuthorizationError('Description', 'invalid_request', undefined);

const err2 = new TokenError(undefined, 'invalid_request', undefined);

const err3 = new InternalOAuthError('Hello', {});
github seanfisher / passport-microsoft / lib / strategy.js View on Github external
function (err, body, res) {

            if (err) {
                return done(new InternalOAuthError('failed to fetch user profile', err))
            }
            try {
                var json = JSON.parse(body)

                var profile = {
                    provider: 'microsoft',
                    name: {}
                }
                profile.id = json.id
                profile.displayName = json.displayName
                profile.name.familyName = json.surname
                profile.name.givenName = json.givenName
                profile.emails = [{ type: 'work', value: json.mail }]

                profile._raw = body
                profile._json = json
github FH-Potsdam / shifted-maps / app / server / services / moves / strategy.js View on Github external
.fail(function(error) {
        done(
          new OAuth2Strategy.InternalOAuthError(
            'Failed to fetch user profile',
            error
          )
        );
      });
  });
github drudge / passport-facebook-token / index.js View on Github external
this._oauth2.get(url, accessToken, function (error, body, res) {
    if (error) return done(new InternalOAuthError('Failed to fetch user profile', error));

    try {
      var json = JSON.parse(body),
        profile = {
          provider: 'facebook',
          id: json.id,
          displayName: json.name || '',
          name: {
            familyName: json.last_name || '',
            givenName: json.first_name || '',
            middleName: json.middle_name || ''
          },
          gender: json.gender || '',
          emails: [{
            value: json.email || ''
          }],
github veritone / veritone-sdk / packages / passport-veritone / lib / strategy.js View on Github external
this._oauth2.get(this._profileUrl, accessToken, function(err, body, res) {
    var json

    if (err) {
      return done(new InternalOAuthError('Failed to fetch current user', err))
    }

    try {
      json = JSON.parse(body)
    } catch (ex) {
      return done(new Error('Failed to parse current user', ex))
    }

    var profile = json
    profile.provider = 'veritone'
    profile.oauthToken = accessToken

    return done(null, profile)
  })
};
github jaredhanson / passport-windowslive / lib / strategy.js View on Github external
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
    var json;
    
    if (err) {
      if (err.data) {
        try {
          json = JSON.parse(err.data);
        } catch (_) {}
      }
        
      if (json && json.error) {
        return done(new LiveConnectAPIError(json.error.message, json.error.code));
      }
      return done(new InternalOAuthError('Failed to fetch user profile', err));
    }
    
    try {
      json = JSON.parse(body);
    } catch (ex) {
      return done(new Error('Failed to parse user profile'));
    }
    
    var profile = Profile.parse(json);
    profile.provider  = 'windowslive';
    profile._raw = body;
    profile._json = json;
    
    done(null, profile);
  });
};
github jaredhanson / passport-github / lib / strategy.js View on Github external
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
    var json;
    
    if (err) {
      if (err.data) {
        try {
          json = JSON.parse(err.data);
        } catch (_) {}
      }
      
      if (json && json.message) {
        return done(new APIError(json.message));
      }
      return done(new InternalOAuthError('Failed to fetch user profile', err));
    }
    
    try {
      json = JSON.parse(body);
    } catch (ex) {
      return done(new Error('Failed to parse user profile'));
    }
    
    var profile = Profile.parse(json);
    profile.provider  = 'github';
    profile._raw = body;
    profile._json = json;


    if (self._scope && self._scope.indexOf('user:email') !== -1) {
      self._oauth2._request('GET', self._userProfileURL + '/emails', { 'Accept': 'application/vnd.github.v3+json' }, '', accessToken, function(err, body, res) {

passport-oauth2

OAuth 2.0 authentication strategy for Passport.

MIT
Latest version published 10 months ago

Package Health Score

70 / 100
Full package analysis