jwt gen & rename fixes
This commit is contained in:
parent
313785b4ac
commit
a165231c47
13 changed files with 101 additions and 41 deletions
|
@ -10,6 +10,7 @@ import UnauthorizedRequestException from "../exceptions/unauthorizedRequestExcep
|
|||
import RefreshService from "../service/refreshService";
|
||||
import WebapiService from "../service/user/webapiService";
|
||||
import ForbiddenRequestException from "../exceptions/forbiddenRequestException";
|
||||
import WebapiCommandHandler from "../command/user/webapi/webapiCommandHandler";
|
||||
|
||||
/**
|
||||
* @description Check authentication status by token
|
||||
|
@ -20,13 +21,15 @@ import ForbiddenRequestException from "../exceptions/forbiddenRequestException";
|
|||
export async function getWebApiAccess(req: Request, res: Response): Promise<any> {
|
||||
const bearer = req.headers.authorization?.split(" ")?.[1] ?? undefined;
|
||||
|
||||
let { expiry } = await WebapiService.getByToken(bearer);
|
||||
let { id, expiry } = await WebapiService.getByToken(bearer);
|
||||
|
||||
if (new Date() > new Date(expiry)) {
|
||||
if (expiry != null && new Date() > new Date(expiry)) {
|
||||
throw new ForbiddenRequestException("api token expired");
|
||||
}
|
||||
|
||||
let accessToken = await JWTHelper.buildWebapiToken(bearer);
|
||||
await WebapiCommandHandler.updateUsage({ id });
|
||||
|
||||
let accessToken = await JWTHelper.buildWebapiToken(bearer, expiry);
|
||||
|
||||
res.json({
|
||||
accessToken,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue