Skip to content

Auth tweaks #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ exports.auth = function (aReq, aRes, aNext) {
var username = aReq.body.username || aReq.session.username;

function auth() {
var authenticate = passport.authenticate(strategy);
var authenticate = passport.authenticate(strategy, { failureRedirect: '/register?stratfail' });

// Just in case some dumbass tries a bad /auth/* url
if (!strategyInstances[strategy]) { return aNext(); }
if (!strategyInstances[strategy]) {
return aNext();
}

authenticate(aReq, aRes);
}
Expand All @@ -61,13 +63,17 @@ exports.auth = function (aReq, aRes, aNext) {
return aNext();
}

if (!username) { return aRes.redirect('/register?noname'); }
if (!username) {
return aRes.redirect('/register?noname');
}
// Clean the username of leading and trailing whitespace,
// and other stuff that is unsafe in a url
username = cleanFilename(username.replace(/^\s+|\s+$/g, ''));

// The username could be empty after the replacements
if (!username) { return aRes.redirect('/register?noname'); }
if (!username) {
return aRes.redirect('/register?noname');
}

// Store the username in the session so we still have it when they
// get back from authentication
Expand Down Expand Up @@ -113,10 +119,10 @@ exports.callback = function (aReq, aRes, aNext) {
// The callback was called improperly
if (!strategy || !username) { return aNext(); }

// Get the passport strategy instance so we can alter the _verfiy method
// Get the passport strategy instance so we can alter the _verify method
strategyInstance = strategyInstances[strategy];

// Hijak the private verify method so we can fuck shit up freely
// Hijack the private verify method so we can fuck shit up freely
// We use this library for things it was never intended to do
if (openIdStrategies[strategy]) {
strategyInstance._verify = function (aId, aDone) {
Expand Down Expand Up @@ -154,7 +160,7 @@ exports.callback = function (aReq, aRes, aNext) {

addSession(aReq, aUser, function () {
if (newstrategy) {
// Allow a user to link to another acount
// Allow a user to link to another account
return aRes.redirect('/auth/' + newstrategy);
} else {
// Delete the username that was temporarily stored
Expand Down