lib/GoogleOAuth2Strategy.js
function GoogleOAuth2Strategy(options, verify) {
        var self = this;

        if (typeof options === 'function') {
            verify = options;
            options = {};
        }
        if (!verify) {
            throw new Error('GoogleOAuth2Strategy requires a verify callback');
        }

        requiredArgs.forEach(function (arg) {
            if (!options[arg.name]) {
                throw new Error(util.format('GoogleOAuth2Strategy requires a [%s]', arg.name));
            } else if (typeof options[arg.name] !== arg.type) {
                throw new Error(util.format('GoogleOAuth2Strategy expects [%s] to be a [%s] but it was a [%s]', arg.name, arg.type, typeof options[arg.name]));
            }
            // If we've passed the checks, go ahead and set it in the current object.
            self[arg.name] = options[arg.name];
        });

        optionalArgs.forEach(function (arg) {
            if (options[arg.name] && typeof options[arg.name] !== arg.type) {
                throw new Error(util.format('GoogleOAuth2Strategy expects [%s] to be a [%s] but it was a [%s]', arg.name, arg.type, typeof options[arg.name]));
            }
            // If we've passed the checks, go ahead and set it in the current object.
            self[arg.name] = options[arg.name];
        });

        if (options.scope && (typeof options.scope !== 'string' && !Array.isArray(options.scope))) {
            throw new Error(util.format('GoogleOAuth2Strategy expects [%s] to be a [%s] but it was a [%s]', 'scope', 'array or string', typeof options.scope));
        }

        self.scope = options.scope || 'https://www.googleapis.com/auth/userinfo.email';

        passport.Strategy.call(self);
        self.name = 'google';
        self.verify = verify;

        if (!self.skipUserProfile) {
            self.googlePlus = gapi.plus('v1');
        }
    }
function GoogleOAuth2Strategy(options, verify) {
        var self = this;

        if (typeof options === 'function') {
            verify = options;
            options = {};
        }
        if (!verify) {
            throw new Error('GoogleOAuth2Strategy requires a verify callback');
        }

        requiredArgs.forEach(function (arg) {
            if (!options[arg.name]) {
                throw new Error(util.format('GoogleOAuth2Strategy requires a [%s]', arg.name));
            } else if (typeof options[arg.name] !== arg.type) {
                throw new Error(util.format('GoogleOAuth2Strategy expects [%s] to be a [%s] but it was a [%s]', arg.name, arg.type, typeof options[arg.name]));
            }
            // If we've passed the checks, go ahead and set it in the current object.
            self[arg.name] = options[arg.name];
        });

        optionalArgs.forEach(function (arg) {
            if (options[arg.name] && typeof options[arg.name] !== arg.type) {
                throw new Error(util.format('GoogleOAuth2Strategy expects [%s] to be a [%s] but it was a [%s]', arg.name, arg.type, typeof options[arg.name]));
            }
            // If we've passed the checks, go ahead and set it in the current object.
            self[arg.name] = options[arg.name];
        });

        if (options.scope && (typeof options.scope !== 'string' && !Array.isArray(options.scope))) {
            throw new Error(util.format('GoogleOAuth2Strategy expects [%s] to be a [%s] but it was a [%s]', 'scope', 'array or string', typeof options.scope));
        }

        self.scope = options.scope || 'https://www.googleapis.com/auth/userinfo.email';

        passport.Strategy.call(self);
        self.name = 'google';
        self.verify = verify;

        if (!self.skipUserProfile) {
            self.googlePlus = gapi.plus('v1');
        }
    }
function GoogleOAuth2Strategy ( options , verify ) { var self = this ; if ( typeof options === 'function' ) { verify = options ; options = { } ; } if ( ! verify ) { throw new Error ( 'GoogleOAuth2Strategy requires a verify callback' ) ; } requiredArgs . forEach ( function ( arg ) { if ( ! options [ arg . name ] ) { throw new Error ( util . format ( 'GoogleOAuth2Strategy requires a [%s]' , arg . name ) ) ; } else if ( typeof options [ arg . name ] !== arg . type ) { throw new Error ( util . format ( 'GoogleOAuth2Strategy expects [%s] to be a [%s] but it was a [%s]' , arg . name , arg . type , typeof options [ arg . name ] ) ) ; } // If we've passed the checks, go ahead and set it in the current object. self [ arg . name ] = options [ arg . name ] ; } ) ; optionalArgs . forEach ( function ( arg ) { if ( options [ arg . name ] && typeof options [ arg . name ] !== arg . type ) { throw new Error ( util . format ( 'GoogleOAuth2Strategy expects [%s] to be a [%s] but it was a [%s]' , arg . name , arg . type , typeof options [ arg . name ] ) ) ; } // If we've passed the checks, go ahead and set it in the current object. self [ arg . name ] = options [ arg . name ] ; } ) ; if ( options . scope && ( typeof options . scope !== 'string' && ! Array . isArray ( options . scope ) ) ) { throw new Error ( util . format ( 'GoogleOAuth2Strategy expects [%s] to be a [%s] but it was a [%s]' , 'scope' , 'array or string' , typeof options . scope ) ) ; } self . scope = options . scope || 'https://www.googleapis.com/auth/userinfo.email' ; passport . Strategy . call ( self ) ; self . name = 'google' ; self . verify = verify ; if ( ! self . skipUserProfile ) { self . googlePlus = gapi . plus ( 'v1' ) ; } }
Creates an instance of `GoogleOAuth2Strategy`.

The Google OAuth 2.0  authentication strategy authenticates requests by delegating
to Google's OAuth 2.0 authentication implementation in their Node.JS API.

OAuth 2.0 provides a facility for delegated authentication, whereby users can
authenticate using a third-party service such as Facebook.  Delegating in
this manner involves a sequence of events, including redirecting the user to
the third-party service for authorization.  Once authorization has been
granted, the user is redirected back to the application and an authorization
code can be used to obtain credentials.

Applications must supply a `verify` callback, for which the function
signature is:

function(accessToken, refreshToken, profile, done) { ... }

The verify callback is responsible for finding or creating the user, and
invoking `done` with the following arguments:

done(err, user, info);

`user` should be set to `false` to indicate an authentication failure.
Additional `info` can optionally be passed as a third argument, typically
used to display informational messages.  If an exception occured, `err`
should be set.

Options:
- `clientId`          `String` identifies the client to the service provider **Required**
- `clientSecret`      `String` secret used to establish ownershup of the client identifier **Required**
- `callbackURL`       `String` URL to which the service provider will redirect the user after obtaining authorization. **Required**
- `accessType`        `String` Type of access to be requested from the service provider. Can be `online` (default) or `offline` (gets refresh_token) _Optional_
- `scope`             `String` or `Array` representing the permission scopes to request access to. (default: `https://www.googleapis.com/auth/userinfo.email`) _Optional_
- `skipUserProfile`   `Boolean` If set to false, profile information will be retrieved from Google+. (default: `true`) _Optional_
- `passReqToCallback` `Boolean` When `true`, `req` is the first argument to the verify callback (default: `false`)

Examples:
passport.use(new GoogleOAuth2Strategy({
clientID: '123-456-789',
clientSecret: 'shhh-its-a-secret',
callbackURL: 'https://www.example.com/auth/example/callback'
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate(..., function (err, user) {
done(err, user);
});
}
));

@constructor
@param {Object} options
@param {Function} verify
@api public
Creates an instance of GoogleOAuth2Strategy .