icynet-auth-server/src/decorators/scope.decorator.ts

15 lines
494 B
TypeScript

import { OAuth2AccessToken } from '@icynet/oauth2-provider';
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
/**
* Get the OAuth2 access token scope from the response.
* Requires the OAuth2 guard or bearer middleware!
*/
export const Scope = createParamDecorator(
(data: unknown, ctx: ExecutionContext) => {
const response = ctx.switchToHttp().getResponse();
const token = response.locals.accessToken as OAuth2AccessToken;
return token.scope;
},
);