From 1df0392d45e502a8e361a11760c0cd25397a6340 Mon Sep 17 00:00:00 2001 From: Brian Dopson Date: Thu, 11 Mar 2021 21:19:39 -0500 Subject: [PATCH] Add support custom params during token exchange --- .../callback-handling/code-flow-callback-handler.service.ts | 6 ++++-- .../src/lib/utils/url/url.service.ts | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/projects/angular-auth-oidc-client/src/lib/flows/callback-handling/code-flow-callback-handler.service.ts b/projects/angular-auth-oidc-client/src/lib/flows/callback-handling/code-flow-callback-handler.service.ts index 532ff12d0..272dc2132 100644 --- a/projects/angular-auth-oidc-client/src/lib/flows/callback-handling/code-flow-callback-handler.service.ts +++ b/projects/angular-auth-oidc-client/src/lib/flows/callback-handling/code-flow-callback-handler.service.ts @@ -75,8 +75,10 @@ export class CodeFlowCallbackHandlerService { let headers: HttpHeaders = new HttpHeaders(); headers = headers.set('Content-Type', 'application/x-www-form-urlencoded'); - - const bodyForCodeFlow = this.urlService.createBodyForCodeFlowCodeRequest(callbackContext.code); + const bodyForCodeFlow = this.urlService.createBodyForCodeFlowCodeRequest( + callbackContext.code, + this.configurationProvider.openIDConfiguration?.customParams + ); return this.dataService.post(tokenEndpoint, bodyForCodeFlow, headers).pipe( switchMap((response) => { diff --git a/projects/angular-auth-oidc-client/src/lib/utils/url/url.service.ts b/projects/angular-auth-oidc-client/src/lib/utils/url/url.service.ts index 590784ee8..927e1bfcf 100644 --- a/projects/angular-auth-oidc-client/src/lib/utils/url/url.service.ts +++ b/projects/angular-auth-oidc-client/src/lib/utils/url/url.service.ts @@ -153,7 +153,7 @@ export class UrlService { return revocationEndpointUrl; } - createBodyForCodeFlowCodeRequest(code: string): string { + createBodyForCodeFlowCodeRequest(code: string, customParams?: { [p: string]: string | number | boolean }): string { const codeVerifier = this.flowsDataService.getCodeVerifier(); if (!codeVerifier) { this.loggerService.logError(`CodeVerifier is not set `, codeVerifier); @@ -182,6 +182,10 @@ export class UrlService { if (!redirectUrl) { return null; } + if (customParams) { + const customParamText = this.composeCustomParams({ ...customParams }); + return oneLineTrim`${dataForBody}${customParamText}&redirect_uri=${redirectUrl}`; + } return oneLineTrim`${dataForBody}&redirect_uri=${redirectUrl}`; }