UNPKG

@manujdhull/nestjs-pkce-oauth2

Version:

A NestJS plugin to simplify OAuth2 PKCE flow integration, including decorators, guards, and token/session management.

21 lines (20 loc) 914 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OAuthInitiate = void 0; const common_1 = require("@nestjs/common"); const validate_query_1 = require("../utils/validate-query"); exports.OAuthInitiate = (0, common_1.createParamDecorator)((_data, ctx) => { const request = ctx.switchToHttp().getRequest(); (0, validate_query_1.assertQueryParams)(['code_challenge', 'code_challenge_method', 'state'], request.query); const { code_challenge, code_challenge_method, state } = request.query; if (typeof code_challenge !== 'string' || typeof code_challenge_method !== 'string' || typeof state !== 'string') { throw new common_1.BadRequestException('Invalid query parameter types in OAuth initiate request.'); } return { codeChallenge: code_challenge, codeChallengeMethod: code_challenge_method, state, }; });