1 | "use strict";
|
2 |
|
3 |
|
4 | const Auth = require('./Auth');
|
5 | const Strategy = require('passport-facebook')
|
6 | .Strategy;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | class FacebookAuth extends Auth
|
14 | {
|
15 |
|
16 | |
17 |
|
18 |
|
19 | constructor(options = {})
|
20 | {
|
21 | super('facebook', options);
|
22 | this.description.redirect = true;
|
23 |
|
24 | |
25 |
|
26 |
|
27 | this.facebookClientID = options.facebookClientID;
|
28 |
|
29 | |
30 |
|
31 |
|
32 | this.facebookClientSecret = options.facebookClientSecret;
|
33 | }
|
34 |
|
35 | |
36 |
|
37 |
|
38 | install(app, prefix, passport)
|
39 | {
|
40 | passport.use(new Strategy({
|
41 | clientID: this.facebookClientID,
|
42 | clientSecret: this.facebookClientSecret,
|
43 | callbackURL: `${prefix}/callback.json`,
|
44 | scope: ['email', 'public_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('facebook', {}));
|
52 |
|
53 | app.all(`${prefix}/callback.json`, passport.authenticate('facebook', this.authenticateOptions), this.loggedIn(true));
|
54 | }
|
55 |
|
56 | }
|
57 |
|
58 | module.exports = FacebookAuth;
|