feat: auth role
This commit is contained in:
parent
bd8290b6b1
commit
34c3f27418
1 changed files with 7 additions and 1 deletions
|
|
@ -17,7 +17,7 @@ const jwtVerify = createVerifier({
|
|||
export function expressAuthentication(
|
||||
request: express.Request,
|
||||
securityName: string,
|
||||
_scopes?: string[],
|
||||
scopes?: string[],
|
||||
) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (securityName !== "bearerAuth") reject(new Error("Unknown authentication method."));
|
||||
|
|
@ -34,6 +34,12 @@ export function expressAuthentication(
|
|||
return reject(new HttpError(HttpStatusCode.UNAUTHORIZED, "Invalid token provided."));
|
||||
}
|
||||
|
||||
if (scopes && !scopes.every((v) => payload.resource_access[payload.azp].roles.includes(v))) {
|
||||
return reject(
|
||||
new HttpError(HttpStatusCode.FORBIDDEN, "You are not allowed to perform this action."),
|
||||
);
|
||||
}
|
||||
|
||||
return resolve(payload);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue