UNPKG

1.31 kBJavaScriptView Raw
1"use strict";
2
3
4const Auth = require('./Auth');
5const Strategy = require('passport-github2')
6 .Strategy;
7
8/**
9 * OAuth login using githuhb login provider
10 *
11 * Requires ```passport-github2``` package.
12 */
13class GithubAuth extends Auth
14{
15 /**
16 * @param {object} options see Auth class + additional options for email configuration.
17 */
18 constructor(options = {})
19 {
20 super('github', options);
21 this.description.redirect = true;
22 /**
23 * OAuth 2 Client ID
24 */
25 this.githubClientID = options.githubClientID;
26 /**
27 * OAuth 2 Client Secret
28 */
29 this.githubClientSecret = options.githubClientSecret;
30 }
31
32 /**
33 * @override
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
55module.exports = GithubAuth;