Skip to content

Commit

Permalink
Merge pull request #4 from wtfil/master
Browse files Browse the repository at this point in the history
Fixed expired code
  • Loading branch information
eagleeye committed Nov 5, 2015
2 parents 57ea61b + d44f1f0 commit 28d2553
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ module.exports = function(clientId, clientSecret, config) {
authenticate: function(req, res, next) {
var cookie = getCookie(req, cookieName);
var val = cookie ? cookieSign.unsign(cookie, secret): false;
var updateCode = function () {
if (config.autologin) return redirect(ghUrl(req), res);
delete req.github;
return next();
};
req.github = {};
if (val) {
req.github.authenticated = true;
Expand All @@ -209,9 +214,7 @@ module.exports = function(clientId, clientSecret, config) {
}
var u = url.parse(req.url, true);
if (!u.query.code || u.query.state !== ghSecretState) {
if (config.autologin) return redirect(ghUrl(req), res);
delete req.github;
return next();
return updateCode();
}
request.post('https://github.com/login/oauth/access_token', {
headers: {
Expand All @@ -226,6 +229,9 @@ module.exports = function(clientId, clientSecret, config) {
}, function(err, response, body) {
if (err) return next(err);
var resp = url.parse('/?'+body, true);
if (!resp.query.access_token) {
return updateCode();
}
accessToken = resp.query.access_token;

getUser(function(err, ghusr) {
Expand Down

0 comments on commit 28d2553

Please sign in to comment.