UNPKG

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