How to use passport-oauth2

Comprehensive passport-oauth2 code examples:

How to use passport-oauth2.InternalOAuthError:

20
21
22
23
24
25
26
27
28
29
userProfile (accessToken, done) {
  this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
    let json

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

    try {
      json = JSON.parse(body)

How to use passport-oauth2.prototype:

125
126
127
128
129
130
131
132
133
134
135
  // Workaround instead of reimplementing authenticate function
  req.query = {...req.query, ...req.body};
  if (req.body && req.body.user) {
    req.appleProfile = JSON.parse(req.body.user);
  }
  OAuth2Strategy.prototype.authenticate.call(this, req, options);
};


/**
 * Modify the authorization params. Currently adds

How to use passport-oauth2.call:

53
54
55
56
57
58
59
60
61
62
options.tokenURL = options.tokenURL || 'https://appleid.apple.com/auth/token';
options.passReqToCallback =
  options.passReqToCallback === undefined ? true : options.passReqToCallback;

// Make the OAuth call
OAuth2Strategy.call(this, options, verify);
this.name = 'apple';

// Initiliaze the client_secret generator
const _tokenGenerator = new AppleClientSecret(