From 95e7ae61b8d6b28591c57a6136070c00a8669c72 Mon Sep 17 00:00:00 2001 From: clempire1 Date: Thu, 17 Aug 2023 23:30:45 +0530 Subject: [PATCH 1/5] Included authOptions in createBodyForParCodeFlowRequest - url.service.ts --- .../angular-auth-oidc-client/src/lib/utils/url/url.service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 c003c4e3..95ff543e 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 @@ -300,9 +300,10 @@ export class UrlService { createBodyForParCodeFlowRequest( configuration: OpenIdConfiguration, + authOptions?: AuthOptions, customParamsRequest?: { [key: string]: string | number | boolean } ): Observable { - const redirectUrl = this.getRedirectUrl(configuration); + const redirectUrl = this.getRedirectUrl(configuration, authOptions); if (!redirectUrl) { return of(null); From bdc6d1d1b74d2d8ebdc328e739eb59cf445b7d6c Mon Sep 17 00:00:00 2001 From: clempire1 Date: Thu, 17 Aug 2023 23:45:14 +0530 Subject: [PATCH 2/5] Update included authOptions for postParRequest in par-login.service.ts --- .../src/lib/login/par/par-login.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/angular-auth-oidc-client/src/lib/login/par/par-login.service.ts b/projects/angular-auth-oidc-client/src/lib/login/par/par-login.service.ts index 43069922..8d26c956 100644 --- a/projects/angular-auth-oidc-client/src/lib/login/par/par-login.service.ts +++ b/projects/angular-auth-oidc-client/src/lib/login/par/par-login.service.ts @@ -54,7 +54,7 @@ export class ParLoginService { .queryAndStoreAuthWellKnownEndPoints(configuration) .pipe( switchMap(() => - this.parService.postParRequest(configuration, customParams) + this.parService.postParRequest(configuration, authOptions, customParams) ) ) .subscribe((response) => { From 0d808756663877fb44210c1531f6b36b4543dbd0 Mon Sep 17 00:00:00 2001 From: Izahir Clemencia Date: Thu, 17 Aug 2023 23:59:05 +0530 Subject: [PATCH 3/5] included auth Options in createBodyForParCodeFlowRequest --- .../src/lib/utils/url/url.service.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 95ff543e..ba4cbd3e 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 @@ -300,9 +300,7 @@ export class UrlService { createBodyForParCodeFlowRequest( configuration: OpenIdConfiguration, - authOptions?: AuthOptions, - customParamsRequest?: { [key: string]: string | number | boolean } - ): Observable { + authOptions?: AuthOptions): Observable { const redirectUrl = this.getRedirectUrl(configuration, authOptions); if (!redirectUrl) { @@ -353,8 +351,8 @@ export class UrlService { ); } - if (customParamsRequest) { - params = this.appendCustomParams({ ...customParamsRequest }, params); + if (authOptions.customParams) { + params = this.appendCustomParams({ ...authOptions.customParams }, params); } return params.toString(); From 7ce2647a473fb6076744aa35d90450a1e10cd43c Mon Sep 17 00:00:00 2001 From: Izahir Clemencia Date: Fri, 18 Aug 2023 00:00:08 +0530 Subject: [PATCH 4/5] updated pushed authorization request to handle auth options --- .../src/lib/login/par/par-login.service.ts | 12 ++++-------- .../src/lib/login/par/par.service.ts | 5 +++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/projects/angular-auth-oidc-client/src/lib/login/par/par-login.service.ts b/projects/angular-auth-oidc-client/src/lib/login/par/par-login.service.ts index 8d26c956..f5708133 100644 --- a/projects/angular-auth-oidc-client/src/lib/login/par/par-login.service.ts +++ b/projects/angular-auth-oidc-client/src/lib/login/par/par-login.service.ts @@ -48,13 +48,11 @@ export class ParLoginService { 'BEGIN Authorize OIDC Flow, no auth data' ); - const { urlHandler, customParams } = authOptions || {}; - this.authWellKnownService .queryAndStoreAuthWellKnownEndPoints(configuration) .pipe( switchMap(() => - this.parService.postParRequest(configuration, authOptions, customParams) + this.parService.postParRequest(configuration, authOptions) ) ) .subscribe((response) => { @@ -76,8 +74,8 @@ export class ParLoginService { return; } - if (urlHandler) { - urlHandler(url); + if (authOptions.urlHandler) { + authOptions.urlHandler(url); } else { this.redirectService.redirectTo(url); } @@ -109,13 +107,11 @@ export class ParLoginService { 'BEGIN Authorize OIDC Flow with popup, no auth data' ); - const { customParams } = authOptions || {}; - return this.authWellKnownService .queryAndStoreAuthWellKnownEndPoints(configuration) .pipe( switchMap(() => - this.parService.postParRequest(configuration, customParams) + this.parService.postParRequest(configuration, authOptions) ), switchMap((response: ParResponse) => { this.loggerService.logDebug( diff --git a/projects/angular-auth-oidc-client/src/lib/login/par/par.service.ts b/projects/angular-auth-oidc-client/src/lib/login/par/par.service.ts index c3ecac4b..cc7b71c3 100644 --- a/projects/angular-auth-oidc-client/src/lib/login/par/par.service.ts +++ b/projects/angular-auth-oidc-client/src/lib/login/par/par.service.ts @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core'; import { Observable, throwError } from 'rxjs'; import { catchError, map, retry, switchMap } from 'rxjs/operators'; import { DataService } from '../../api/data.service'; +import { AuthOptions } from '../../auth-options'; import { OpenIdConfiguration } from '../../config/openid-configuration'; import { LoggerService } from '../../logging/logger.service'; import { StoragePersistenceService } from '../../storage/storage-persistence.service'; @@ -20,7 +21,7 @@ export class ParService { postParRequest( configuration: OpenIdConfiguration, - customParams?: { [key: string]: string | number | boolean } + authOptions: AuthOptions ): Observable { let headers: HttpHeaders = new HttpHeaders(); @@ -50,7 +51,7 @@ export class ParService { } return this.urlService - .createBodyForParCodeFlowRequest(configuration, customParams) + .createBodyForParCodeFlowRequest(configuration, authOptions) .pipe( switchMap((data) => { return this.dataService From 7a846b3bc920008e2d913558ddf92eb5ffb2e4ca Mon Sep 17 00:00:00 2001 From: Izahir Clemencia Date: Fri, 18 Aug 2023 12:22:22 +0530 Subject: [PATCH 5/5] Updated testcases & bugfixes --- .../src/lib/login/par/par-login.service.spec.ts | 12 +++++++++--- .../src/lib/login/par/par.service.ts | 2 +- .../src/lib/utils/url/url.service.spec.ts | 4 +++- .../src/lib/utils/url/url.service.ts | 10 +++++++--- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/projects/angular-auth-oidc-client/src/lib/login/par/par-login.service.spec.ts b/projects/angular-auth-oidc-client/src/lib/login/par/par-login.service.spec.ts index 064e2481..3f03950c 100644 --- a/projects/angular-auth-oidc-client/src/lib/login/par/par-login.service.spec.ts +++ b/projects/angular-auth-oidc-client/src/lib/login/par/par-login.service.spec.ts @@ -144,7 +144,9 @@ describe('ParLoginService', () => { }); expect(result).toBeUndefined(); - expect(spy).toHaveBeenCalledOnceWith(config, { some: 'thing' }); + expect(spy).toHaveBeenCalledOnceWith(config, { + customParams: { some: 'thing' }, + }); })); it('returns undefined and logs error when no url could be created', waitForAsync(() => { @@ -184,6 +186,8 @@ describe('ParLoginService', () => { responseType: 'stubValue', }; + const authOptions = {}; + spyOn( authWellKnownService, 'queryAndStoreAuthWellKnownEndPoints' @@ -195,7 +199,7 @@ describe('ParLoginService', () => { spyOn(urlService, 'getAuthorizeParUrl').and.returnValue('some-par-url'); const spy = spyOn(redirectService, 'redirectTo'); - service.loginPar(config); + service.loginPar(config, authOptions); expect(spy).toHaveBeenCalledOnceWith('some-par-url'); })); @@ -306,7 +310,9 @@ describe('ParLoginService', () => { }) .subscribe({ error: (err) => { - expect(spy).toHaveBeenCalledOnceWith(config, { some: 'thing' }); + expect(spy).toHaveBeenCalledOnceWith(config, { + customParams: { some: 'thing' }, + }); expect(err.message).toBe( "Could not create URL with param requestUri: 'url'" ); diff --git a/projects/angular-auth-oidc-client/src/lib/login/par/par.service.ts b/projects/angular-auth-oidc-client/src/lib/login/par/par.service.ts index cc7b71c3..be3c4ccc 100644 --- a/projects/angular-auth-oidc-client/src/lib/login/par/par.service.ts +++ b/projects/angular-auth-oidc-client/src/lib/login/par/par.service.ts @@ -21,7 +21,7 @@ export class ParService { postParRequest( configuration: OpenIdConfiguration, - authOptions: AuthOptions + authOptions?: AuthOptions ): Observable { let headers: HttpHeaders = new HttpHeaders(); diff --git a/projects/angular-auth-oidc-client/src/lib/utils/url/url.service.spec.ts b/projects/angular-auth-oidc-client/src/lib/utils/url/url.service.spec.ts index 66de32b5..49e7434f 100644 --- a/projects/angular-auth-oidc-client/src/lib/utils/url/url.service.spec.ts +++ b/projects/angular-auth-oidc-client/src/lib/utils/url/url.service.spec.ts @@ -1348,7 +1348,9 @@ describe('UrlService Tests', () => { ); const resultObs$ = service.createBodyForParCodeFlowRequest(config, { - any: 'otherThing', + customParams: { + any: 'otherThing', + }, }); resultObs$.subscribe((result) => { 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 ba4cbd3e..b602e48c 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 @@ -300,7 +300,8 @@ export class UrlService { createBodyForParCodeFlowRequest( configuration: OpenIdConfiguration, - authOptions?: AuthOptions): Observable { + authOptions?: AuthOptions + ): Observable { const redirectUrl = this.getRedirectUrl(configuration, authOptions); if (!redirectUrl) { @@ -351,8 +352,11 @@ export class UrlService { ); } - if (authOptions.customParams) { - params = this.appendCustomParams({ ...authOptions.customParams }, params); + if (authOptions?.customParams) { + params = this.appendCustomParams( + { ...authOptions.customParams }, + params + ); } return params.toString();