-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
62 lines (50 loc) · 1.63 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Created by Parikansh on 01/08/2017.
*/
const express = require('express');
const app = express();
const bp = require('body-parser');
const session = require('express-session');
const path = require('path');
const passport = require('passport');
const FacebookStrategy = require('passport-facebook').Strategy;
const FB = require('fb');
app.use(express.static('public_static'));
app.use(bp.json());
app.use(bp.urlencoded({extended: true}));
app.use(session({secret: 'secretcsi',
resave: false,
saveUninitialized: true}));
app.use(passport.initialize());
app.use(passport.session());
const route = {
secure : require('./route/secure')
};
// Every file of secure route is FB authenticated
app.use('/secure',route.secure);
/* USAGE OF PASSPORT.js */
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(user, done) {
done(null, user);
});
passport.use(new FacebookStrategy({
clientID: '140795106503697',
clientSecret: '7aa0ade9a2c1a787ee0a4b7d0670e176',
callbackURL: "http://localhost:5000/auth/facebook/callback"
},
function(accessToken, refreshToken, profile, done) {
FB.setAccessToken(accessToken);
done(null, profile);
}
));
app.get('/auth/facebook', passport.authenticate('facebook'));
// Passport login authenticate
app.get('/auth/facebook/callback',
passport.authenticate('facebook', { successRedirect: '/secure/posts',
failureRedirect: '/' })
);
app.listen(5000,function () {
console.log("Server is running on 5000");
});