1 | "use strict";
|
2 |
|
3 |
|
4 | const Auth = require('./Auth');
|
5 | const Strategy = require('passport-google-oauth2')
|
6 | .Strategy;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | class GoogleAuth extends Auth
|
14 | {
|
15 |
|
16 | |
17 |
|
18 |
|
19 | constructor(options = {})
|
20 | {
|
21 | super('google', options);
|
22 | this.description.redirect = true;
|
23 |
|
24 | |
25 |
|
26 |
|
27 | this.googleClientID = options.googleClientID;
|
28 |
|
29 | |
30 |
|
31 |
|
32 | this.googleClientSecret = options.googleClientSecret;
|
33 | }
|
34 |
|
35 | |
36 |
|
37 |
|
38 | install(app, prefix, passport)
|
39 | {
|
40 | passport.use(new Strategy({
|
41 | clientID: this.googleClientID,
|
42 | clientSecret: this.googleClientSecret,
|
43 | callbackURL: `${prefix}/callback.json`,
|
44 | scope: ['email', 'profile'],
|
45 | state: true,
|
46 | passReqToCallback: true,
|
47 | proxy: true,
|
48 | }, (req, accessToken, refreshToken, profile, done) =>
|
49 | this.handleUserLoginByProfile(null, profile, done, req)));
|
50 |
|
51 | app.all(`${prefix}/login.json`, passport.authenticate('google', {}));
|
52 |
|
53 | app.all(`${prefix}/callback.json`, passport.authenticate('google', this.authenticateOptions), this.loggedIn(true));
|
54 | }
|
55 |
|
56 | }
|
57 |
|
58 | module.exports = GoogleAuth;
|