UNPKG

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