fix issue #165
This commit is contained in:
parent
0a296aba07
commit
b9dbb6d678
@ -1,7 +1,9 @@
|
|||||||
# PeerServer Changelog
|
# PeerServer Changelog
|
||||||
|
|
||||||
|
|
||||||
### vNEXT 0.5.0
|
### 0.5.0
|
||||||
|
|
||||||
|
* Fix: http api not working - #163 Thanks riscoss63
|
||||||
|
|
||||||
* Change: use "/" instead of "/myapp" as a default value for config's `path` option
|
* Change: use "/" instead of "/myapp" as a default value for config's `path` option
|
||||||
|
|
||||||
|
34
dist/src/api/middleware/auth/index.js
vendored
34
dist/src/api/middleware/auth/index.js
vendored
@ -5,23 +5,23 @@ class AuthMiddleware {
|
|||||||
constructor(config, realm) {
|
constructor(config, realm) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.realm = realm;
|
this.realm = realm;
|
||||||
}
|
this.handle = (req, res, next) => {
|
||||||
handle(req, res, next) {
|
const { id, token, key } = req.params;
|
||||||
const { id, token, key } = req.params;
|
if (key !== this.config.key) {
|
||||||
if (key !== this.config.key) {
|
return res.status(401).send(enums_1.Errors.INVALID_KEY);
|
||||||
return res.status(401).send(enums_1.Errors.INVALID_KEY);
|
}
|
||||||
}
|
if (!id) {
|
||||||
if (!id) {
|
return res.sendStatus(401);
|
||||||
return res.sendStatus(401);
|
}
|
||||||
}
|
const client = this.realm.getClientById(id);
|
||||||
const client = this.realm.getClientById(id);
|
if (!client) {
|
||||||
if (!client) {
|
return res.sendStatus(401);
|
||||||
return res.sendStatus(401);
|
}
|
||||||
}
|
if (client.getToken() && token !== client.getToken()) {
|
||||||
if (client.getToken() && token !== client.getToken()) {
|
return res.status(401).send(enums_1.Errors.INVALID_TOKEN);
|
||||||
return res.status(401).send(enums_1.Errors.INVALID_TOKEN);
|
}
|
||||||
}
|
next();
|
||||||
next();
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.AuthMiddleware = AuthMiddleware;
|
exports.AuthMiddleware = AuthMiddleware;
|
||||||
|
@ -8,7 +8,7 @@ export class AuthMiddleware implements IMiddleware {
|
|||||||
|
|
||||||
constructor(private readonly config: IConfig, private readonly realm: IRealm) { }
|
constructor(private readonly config: IConfig, private readonly realm: IRealm) { }
|
||||||
|
|
||||||
public handle(req: express.Request, res: express.Response, next: express.NextFunction): any {
|
public handle = (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
const { id, token, key } = req.params;
|
const { id, token, key } = req.params;
|
||||||
|
|
||||||
if (key !== this.config.key) {
|
if (key !== this.config.key) {
|
||||||
@ -30,6 +30,6 @@ export class AuthMiddleware implements IMiddleware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user