Skip to content

Commit f90e946

Browse files
committed
refactor(oidc-client): move useParFlow derivation out of authorizeµ parameter default
1 parent 15d616d commit f90e946

2 files changed

Lines changed: 32 additions & 24 deletions

File tree

packages/oidc-client/src/lib/authorize.request.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ export function createParAuthorizeUrlµ(
139139
* @param log - The CustomLogger used for debug and error trace.
140140
* @param store - The RTK client store providing the `oidcApi` endpoints.
141141
* @param options - Optional request-level overrides for the authorize call.
142-
* @param useParFlow - Computed default that selects PAR when either the
143-
* server requires it or the caller opted in. Exposed for testability.
142+
* @param useParFlow - Boolean resolved by the caller (e.g. `client.store`)
143+
* indicating whether to use the PAR flow. The caller owns the derivation
144+
* logic (`config.par ?? require_pushed_authorization_requests === true`);
145+
* this function simply routes on the resolved value.
144146
* @returns A `Micro` that resolves to an `AuthorizationSuccess` containing
145147
* the `code` and `state`, or fails with a typed `AuthorizationError`.
146148
*/
@@ -149,8 +151,8 @@ export function authorizeµ(
149151
config: OidcConfig,
150152
log: CustomLogger,
151153
store: ClientStore,
152-
options?: GetAuthorizationUrlOptions,
153-
useParFlow = config.par ?? wellknown?.require_pushed_authorization_requests === true,
154+
options: GetAuthorizationUrlOptions | undefined,
155+
useParFlow: boolean,
154156
): Micro.Micro<AuthorizationSuccess, AuthorizationError, never> {
155157
const parDispatchOptions: GetAuthorizationUrlOptions = {
156158
clientId: config.clientId,

packages/oidc-client/src/lib/authorize.request.utils.test.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -419,28 +419,34 @@ it.effect('authorizeµ uses standard flow when useParFlow=false', () =>
419419
}),
420420
);
421421

422-
it.effect('authorizeµ defaults to PAR when wellknown requires it and useParFlow not passed', () =>
423-
Micro.gen(function* () {
424-
const requestUri = 'urn:ietf:params:oauth:request_uri:required-par-test';
425-
const authorizeResponse = { code: 'req-par-code', state: 'req-par-state' };
426-
const wkRequiresPar: WellknownResponse = {
427-
...wellknownWithPar,
428-
require_pushed_authorization_requests: true,
429-
};
422+
it.effect(
423+
'authorizeµ uses PAR flow when caller passes useParFlow=true (e.g. server requires PAR)',
424+
() =>
425+
Micro.gen(function* () {
426+
const requestUri = 'urn:ietf:params:oauth:request_uri:required-par-test';
427+
const authorizeResponse = { code: 'req-par-code', state: 'req-par-state' };
430428

431-
vi.stubGlobal('sessionStorage', sessionStorageStub);
432-
vi.mocked(mockStore.dispatch)
433-
.mockResolvedValueOnce({
434-
data: { request_uri: requestUri, expires_in: 60 },
435-
} as unknown as ReturnType<typeof mockStore.dispatch>)
436-
.mockResolvedValueOnce({
437-
data: authorizeResponse,
438-
} as unknown as ReturnType<typeof mockStore.dispatch>);
429+
vi.stubGlobal('sessionStorage', sessionStorageStub);
430+
vi.mocked(mockStore.dispatch)
431+
.mockResolvedValueOnce({
432+
data: { request_uri: requestUri, expires_in: 60 },
433+
} as unknown as ReturnType<typeof mockStore.dispatch>)
434+
.mockResolvedValueOnce({
435+
data: authorizeResponse,
436+
} as unknown as ReturnType<typeof mockStore.dispatch>);
439437

440-
const result = yield* authorizeµ(wkRequiresPar, config, mockLog, mockStore);
441-
expect(result).toStrictEqual(authorizeResponse);
442-
expect(mockStore.dispatch).toHaveBeenCalledTimes(2);
443-
}),
438+
// useParFlow=true is what client.store derives when require_pushed_authorization_requests===true
439+
const result = yield* authorizeµ(
440+
wellknownWithPar,
441+
config,
442+
mockLog,
443+
mockStore,
444+
undefined,
445+
true,
446+
);
447+
expect(result).toStrictEqual(authorizeResponse);
448+
expect(mockStore.dispatch).toHaveBeenCalledTimes(2);
449+
}),
444450
);
445451

446452
it.effect(

0 commit comments

Comments
 (0)