Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions lib/model/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ Host.ensureHost = function(hostname, callback) {
);
};

Host.prototype.destroyHost = function(callback) {

var host = this;

Step(
function() {
Credentials.getForHost(URLMaker.hostname, host, this);
},
function(err, cred) {
if (err) throw err;
cred.del(this);
},
function(err) {
host.del(this);
},
callback
);
};

Host.discover = function(hostname, callback) {

var props = {
Expand Down
12 changes: 9 additions & 3 deletions routes/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,16 @@ var handleRemote = function(req, res, next) {
host.getRequestToken(this);
},
function(err, rt) {
if (err) {
next(err);
} else {
if (!err) {
res.redirect(host.authorizeURL(rt));
} else if (err.statusCode) {
if (host && err.statusCode === 400) {
req.log.warn("Invalid or old host credentials", err);
host.destroyHost(req.log.error);
}
next(new HTTPError(err.data, err.statusCode));
} else {
next(err);
}
}
);
Expand Down