Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 1x 1x 2x 2x 2x 2x 2x 1x | "use strict";
const Auth = require('./Auth');
const Strategy = require('passport-google-oauth2')
.Strategy;
/**
* OAuth login using google login provider
*
* Requires ```passport-google-oauth2``` package.
*/
class GoogleAuth extends Auth
{
/**
* @param {object} options see Auth class + additional options for email configuration.
*/
constructor(options = {})
{
super('google', options);
this.description.redirect = true;
/**
* OAuth 2 Client ID
*/
this.googleClientID = options.googleClientID;
/**
* OAuth 2 Client Secret
*/
this.googleClientSecret = options.googleClientSecret;
/**
* Should it construct urls based on proxy headers.
*/
this.proxy = options.proxy || false;
}
/**
* @override
*/
install(app, prefix, passport)
{
passport.use(new Strategy({
clientID: this.googleClientID,
clientSecret: this.googleClientSecret,
callbackURL: `${prefix}/callback.json`,
scope: ['email', 'profile'],
state: true,
passReqToCallback: true,
proxy: this.proxy,
}, (req, accessToken, refreshToken, profile, done) =>
this.handleUserLoginByProfile(null, profile, done, req)));
app.all(`${prefix}/login.json`, passport.authenticate('google', {}));
app.all(`${prefix}/callback.json`, passport.authenticate('google', this.authenticateOptions), this.loggedIn(true));
}
}
module.exports = GoogleAuth;
|