-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
90 lines (81 loc) · 3.25 KB
/
app.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var express = require('express'),
path = require('path'),
http = require('http'),
passport = require('passport'),
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
nconf = require('nconf');
//NConf Configuration
nconf.env().file({ file: 'settings.json' });
//From: https://github.com/jaredhanson/passport-google/blob/master/examples/signon/app.js
// Passport session setup.
// To support persistent login sessions, Passport needs to be able to
// serialize users into and deserialize users out of the session. Typically,
// this will be as simple as storing the user ID when serializing, and finding
// the user by ID when deserializing. However, since this example does not
// have a database of user records, the complete Google profile is serialized
// and deserialized.
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
// Use the GoogleStrategy within Passport.
// Strategies in passport require a `validate` function, which accept
// credentials (in this case, an OpenID identifier and profile), and invoke a
// callback with a user object.
passport.use(new GoogleStrategy({
prompt: 'select_account',
clientID: nconf.get("Google:ClientID"),
clientSecret: nconf.get("Google:ClientSecret"),
callbackURL: nconf.get("host:headURL") + "/auth/google/callback"
//callbackURL: "http://localhost:3000/auth/google/callback"
// ************************************************
// Comment out one of the following above.
// When pushing make sure nconf.get("host:headURL") + "/auth/google/callback"
// When running locally use "http://localhost:3000/auth/google/callback"
// ************************************************
},
function (accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
console.log(JSON.stringify(profile));
console.log(profile._json.hd);
if (profile._json.hd == 'bandwidth.com') {
return done(null, profile);
} else {
return done(null, null);
}
});
}
));
//Express Configuration
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/html/src');
app.set('view engine', 'jade');
app.use(express.favicon());
//app.use(express.logger('dev'));
app.use(express.cookieParser());
app.use(express.urlencoded());
app.use(express.json());
app.use(express.methodOverride());
app.use(express.session({ secret: 'BWOCEM' }));
// Initialize Passport! Also use passport.session() middleware, to support
// persistent login sessions (recommended).
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'html/includes')));
app.engine('html', require('ejs').renderFile);
});
app.configure('development', function(){
app.use(express.errorHandler());
});
require('./routes/twilio.js')(app);
require('./routes/Application.js')(app);
require('./routes/Staff.js')(app);
require('./routes/Gui.js')(app);
require('./routes/Auth.js')(app);
module.exports = app;