mirror of https://github.com/embarklabs/embark.git
add console command to get token
This commit is contained in:
parent
faf09b7d39
commit
e68feb81af
|
@ -4,26 +4,39 @@ class Authenticator {
|
||||||
|
|
||||||
constructor(embark, _options) {
|
constructor(embark, _options) {
|
||||||
this.authToken = uuid();
|
this.authToken = uuid();
|
||||||
|
this.embark = embark;
|
||||||
|
this.logger = embark.logger;
|
||||||
|
|
||||||
|
this.registerCalls();
|
||||||
embark.events.once('outputDone', () => {
|
embark.events.once('outputDone', () => {
|
||||||
embark.logger.info(__('Access the web backend with the following url: %s',
|
embark.logger.info(__('Access the web backend with the following url: %s',
|
||||||
('http://localhost:8000/embark?token=' + this.authToken).underline));
|
('http://localhost:8000/embark?token=' + this.authToken).underline));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
embark.registerAPICall(
|
registerCalls() {
|
||||||
|
this.embark.registerAPICall(
|
||||||
'post',
|
'post',
|
||||||
'/embark-api/authenticate',
|
'/embark-api/authenticate',
|
||||||
(req, res) => {
|
(req, res) => {
|
||||||
if (req.body.token !== this.authToken) {
|
if (req.body.token !== this.authToken) {
|
||||||
embark.logger.warn(__('Someone tried and failed to authenticate to the backend'));
|
this.logger.warn(__('Someone tried and failed to authenticate to the backend'));
|
||||||
embark.logger.warn(__('- User-Agent: %s', req.headers['user-agent']));
|
this.logger.warn(__('- User-Agent: %s', req.headers['user-agent']));
|
||||||
embark.logger.warn(__('- Referer: %s', req.headers.referer));
|
this.logger.warn(__('- Referer: %s', req.headers.referer));
|
||||||
return res.status(403).send({error: __('Wrong authentication token')});
|
return res.status(403).send({error: __('Wrong authentication token')});
|
||||||
}
|
}
|
||||||
res.send();
|
res.send();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.embark.registerConsoleCommand((cmd, _options) => {
|
||||||
|
return {
|
||||||
|
match: () => cmd === "token",
|
||||||
|
process: (callback) => {
|
||||||
|
callback(null, __('Your authorisation token: %s', this.authToken));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue