This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
102 lines (87 loc) · 2.81 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
91
92
93
94
95
96
97
98
99
100
101
102
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, githubapi = require('./routes/github-api')
, http = require('http')
, util = require('util')
, passport = require('passport')
, GitHubStrategy = require('passport-github').Strategy
, proxy = require('simple-http-proxy')
, path = require('path');
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
// clientID: '5a821c5ca41b1a27d65b',
// clientSecret: '0902b4d912625069bbcb33f3e49eee295d480951',
passport.use(new GitHubStrategy({
clientID: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
callbackURL: process.env.HOST_NAME + "/auth/github/callback"
},
function(accessToken, refreshToken, profile, done) {
process.nextTick(function () {
return done(null, {"accessToken": accessToken, "refreshToken": refreshToken, "profile": profile});
});
}
));
var app = module.exports = express();
app.configure(function(){
app.set('port', process.env.PORT || 5000);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express['static'](path.join(__dirname, 'public')));
app.use(express['static'](path.join(__dirname, 'build')));
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
// app.use("/github-api", function (req, res, next) {
// if (req.isAuthenticated()) {
// req.headers["authorization"] = "Bearer " + req.user.accessToken;
// }
// next();
// });
// app.use("/github-api", proxy("https://api.github.com"));
// app.use("/api", proxy("https://api.github.com"));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
app.get('/', routes.index);
// app.get('/github-api/repos', githubapi.repos);
app.get('/auth/github',
passport.authenticate('github', { scope: 'repo' }),
function(req, res){
// The request will be redirected to GitHub for authentication, so this
// function will not be called.
});
app.get('/auth/github/callback',
passport.authenticate('github', { failureRedirect: '/' }),
function(req, res) {
res.redirect('/');
});
app.get('/login', ensureAuthenticated, function(req, res){
// res.redirect('/');
});
app.get('/logout', function(req, res){
req.logout();
res.clearCookie('accessToken');
res.redirect('/');
});
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) { return next(); }
res.redirect('/auth/github');
}
if(!process.env.STARTUP) {
app.listen(app.get('port'));
}