Abstraction used by the AuthInterceptor to authorize decaf models.
// costumauthHandler.ts
Example
export class CustomAuthHandler implements AuthHandler {
async authorize(ctx: ExecutionContext, resource: string) {
const req = ctx.switchToHttp().getRequest();
const userRole = req.headers.authorization?.split(" ")[1] as string;
if (!userRole) throw new AuthorizationError("Unauthenticated");
const roles = Metadata.get(Model.get(resource)!, AuthRole);
if (!roles.includes(userRole)) {
throw new AuthorizationError("Unauthorized");
}
}
}
// auth.module.ts
Members
Promise.<void>
|
void
# authorize
Inspect the request context and ensure the caller can access the model.
Inspect the request context and ensure the caller can access the model.
Implementations should throw an AuthorizationError on denial.