From 4a2cc176da7270f9e880a3f09ec22da5bf123771 Mon Sep 17 00:00:00 2001 From: jac50817 <127602075+jac50817@users.noreply.github.com> Date: Wed, 3 Jan 2024 08:02:06 -0300 Subject: [PATCH] feat: support acrValues (#105) * feat: expose AuthConfig acr values * chore: revert prettier changes * chore: apply changes from code-review * chore: revert changes to spec * chore: adds test for acrValues * chore: simplifies some stuff --------- Co-authored-by: Jose Co-authored-by: Leonardo Chaia --- projects/angular-simple-oidc/package.json | 2 +- .../src/lib/config/models.ts | 5 +++ .../lib/oidc-code-flow-client.service.spec.ts | 38 +++++++++++++++++++ .../src/lib/oidc-code-flow-client.service.ts | 1 + 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/projects/angular-simple-oidc/package.json b/projects/angular-simple-oidc/package.json index a293ae3..28bff95 100644 --- a/projects/angular-simple-oidc/package.json +++ b/projects/angular-simple-oidc/package.json @@ -1,6 +1,6 @@ { "name": "angular-simple-oidc", - "version": "12.0.0-alpha", + "version": "12.0.1-alpha", "description": "Angular Library implementing Open Id Connect specification. Code Flow, Refresh Tokens, Session Management, Discovery Document.", "repository": { "type": "git", diff --git a/projects/angular-simple-oidc/src/lib/config/models.ts b/projects/angular-simple-oidc/src/lib/config/models.ts index 8a05ad5..c71c752 100644 --- a/projects/angular-simple-oidc/src/lib/config/models.ts +++ b/projects/angular-simple-oidc/src/lib/config/models.ts @@ -54,4 +54,9 @@ export interface AuthConfig { * `${window.location.protocol}//${window.location.host}${window.location.pathname}` */ baseUrl?: string; + + /** + * The authentication context class reference parameters. + */ + acrValues?: string; } diff --git a/projects/angular-simple-oidc/src/lib/oidc-code-flow-client.service.spec.ts b/projects/angular-simple-oidc/src/lib/oidc-code-flow-client.service.spec.ts index 8c12404..3d63997 100644 --- a/projects/angular-simple-oidc/src/lib/oidc-code-flow-client.service.spec.ts +++ b/projects/angular-simple-oidc/src/lib/oidc-code-flow-client.service.spec.ts @@ -309,6 +309,44 @@ describe('OidcCodeFlowClientService', () => { preRedirectUrl: currentLocation }); })); + + it('Should generate the url using provided acr values', fakeAsync(() => { + const doc: Partial = { + authorization_endpoint: 'http://idp/authorize' + }; + + discoveryDocSpy.and.returnValue(of(doc)); + + const urlResult = { + codeChallenge: 'challenge', + codeVerifier: 'verifier', + nonce: 'nonce', + state: 'state', + url: 'url' + }; + + tokenUrlSpy.createAuthorizeUrl.and.returnValue(urlResult); + + const redirectUri = 'redirect'; + const idTokenHint = 'id-token-hint'; + const prompt = 'prompt'; + const acrValues = 'needs=wifi' + + codeFlowClient.generateCodeFlowMetadata({ redirectUri, idTokenHint, prompt, acrValues }) + .subscribe(); + flush(); + + expect(tokenUrlSpy.createAuthorizeUrl) + .toHaveBeenCalledWith(doc.authorization_endpoint, { + clientId: config.clientId, + responseType: 'code', + scope: config.scope, + redirectUri: redirectUri, + idTokenHint: idTokenHint, + prompt: prompt, + acrValues + }); + })); }); describe('Code Flow Callback', () => { diff --git a/projects/angular-simple-oidc/src/lib/oidc-code-flow-client.service.ts b/projects/angular-simple-oidc/src/lib/oidc-code-flow-client.service.ts index 57ca2a9..0fb2d3d 100644 --- a/projects/angular-simple-oidc/src/lib/oidc-code-flow-client.service.ts +++ b/projects/angular-simple-oidc/src/lib/oidc-code-flow-client.service.ts @@ -79,6 +79,7 @@ export class OidcCodeFlowClient { clientId: config.clientId, scope: config.scope, responseType: 'code', + ...config.acrValues && { acrValues: config.acrValues }, ...params, })), take(1),