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