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

14 lines
458 B
TypeScript

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