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