mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 06:16:01 +00:00
Change back how auth works for websockets.
As it turns out, a websocket request doesn't contain some of the hashable properties in order to be validated. Because of that, we'll still use tokens here until we find a better way to do it.
This commit is contained in:
parent
1c85d898b7
commit
53bc4d945a
@ -73,12 +73,17 @@ class Authenticator {
|
|||||||
(`http://${host}:${port}/embark?token=${this.authToken}`.underline)));
|
(`http://${host}:${port}/embark?token=${this.authToken}`.underline)));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.events.setCommandHandler('authenticator:authorize', (req, cb) => {
|
this.events.setCommandHandler('authenticator:authorize', (req, res, cb) => {
|
||||||
|
let authenticated = false;
|
||||||
|
if(!res.send) {
|
||||||
|
authenticated = (this.authToken === req.protocol);
|
||||||
|
} else {
|
||||||
let hash = self.generateRequestHash(req);
|
let hash = self.generateRequestHash(req);
|
||||||
if(hash !== req.headers['x-embark-request-hash']) {
|
authenticated = (hash === req.headers['x-embark-request-hash']);
|
||||||
return cb(ERROR_OBJ);
|
|
||||||
}
|
}
|
||||||
cb();
|
|
||||||
|
if(authenticated) return cb();
|
||||||
|
cb(ERROR_OBJ);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,8 +162,7 @@ class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
applyAPIFunction(cb, req, res) {
|
applyAPIFunction(cb, req, res) {
|
||||||
const authToken = (!res.send) ? req.protocol : req.headers.authorization;
|
this.events.request('authenticator:authorize', req, res, (err) => {
|
||||||
this.events.request('authenticator:authorize', authToken, (err) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
const send = res.send ? res.send.bind(res) : req.send.bind(req); // WS only has the first params
|
const send = res.send ? res.send.bind(res) : req.send.bind(req); // WS only has the first params
|
||||||
return send(err);
|
return send(err);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user