Skip to content

Commit 41a0e28

Browse files
committed
feat(oidc-client): improve Effect usage
1 parent 316458c commit 41a0e28

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
<<<<<<< HEAD
12
/*
23
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
34
*
45
* This software may be modified and distributed under the terms
56
* of the MIT license. See the LICENSE file for details.
67
*/
8+
=======
9+
>>>>>>> f35d74ad (feat(oidc-client): improve Effect usage)
710
import { CustomLogger } from '@forgerock/sdk-logger';
811
import { GetAuthorizationUrlOptions } from '@forgerock/sdk-oidc';
912
import { Micro } from 'effect';
@@ -19,18 +22,39 @@ import {
1922
import type { WellKnownResponse } from '@forgerock/sdk-types';
2023

2124
import type { OidcConfig } from './config.types.js';
25+
<<<<<<< HEAD
2226
import { AuthorizeErrorResponse, AuthorizeSuccessResponse } from './authorize.request.types.js';
27+
=======
28+
import { AuthorizeSuccessResponse } from './authorize.request.types.js';
29+
>>>>>>> f35d74ad (feat(oidc-client): improve Effect usage)
2330

2431
export async function authorizeµ(
2532
wellknown: WellKnownResponse,
2633
config: OidcConfig,
2734
log: CustomLogger,
2835
options?: GetAuthorizationUrlOptions,
2936
) {
37+
<<<<<<< HEAD
3038
return buildAuthorizeOptionsµ(wellknown, config, options).pipe(
3139
Micro.flatMap(([url, config, options]) => createAuthorizeUrlµ(url, config, options)),
3240
Micro.tap((url) => log.debug('Authorize URL created', url)),
3341
Micro.tapError((url) => Micro.sync(() => log.error('Error creating authorize URL', url))),
42+
=======
43+
const buildAuthorizeRequestµ = buildAuthorizeOptionsµ(wellknown, config, options).pipe(
44+
Micro.flatMap(([url, config, options]) => createAuthorizeUrlµ(url, config, options)),
45+
(effect) => {
46+
return Micro.matchEffect(effect, {
47+
onSuccess: (url) => {
48+
log.debug('Created authorization URL', { url });
49+
return effect;
50+
},
51+
onFailure: (error) => {
52+
log.error('Error creating authorization URL', { error });
53+
return effect;
54+
},
55+
});
56+
},
57+
>>>>>>> f35d74ad (feat(oidc-client): improve Effect usage)
3458
Micro.flatMap(([url, config, options]) => {
3559
if (options.responseMode === 'pi.flow') {
3660
/**
@@ -40,12 +64,24 @@ export async function authorizeµ(
4064
*/
4165
return authorizeFetchµ(url).pipe(
4266
Micro.flatMap((response) => {
67+
<<<<<<< HEAD
4368
if ('authorizeResponse' in response) {
4469
log.debug('Received authorize response', response.authorizeResponse);
4570
return Micro.succeed(response.authorizeResponse);
4671
}
4772
log.error('Error in authorize response', response);
4873
return Micro.fail(createAuthorizeErrorµ(response, wellknown, config, options));
74+
=======
75+
return Micro.gen(function* () {
76+
if ('authorizeResponse' in response) {
77+
log.debug('Received authorize response', response.authorizeResponse);
78+
return yield* Micro.succeed(response.authorizeResponse as AuthorizeSuccessResponse);
79+
}
80+
log.error('Error in authorize response', response);
81+
const errorResponse = response as { error: string; error_description: string };
82+
return yield* createAuthorizeErrorµ(errorResponse, wellknown, config, options);
83+
});
84+
>>>>>>> f35d74ad (feat(oidc-client): improve Effect usage)
4985
}),
5086
);
5187
} else {
@@ -55,16 +91,33 @@ export async function authorizeµ(
5591
*/
5692
return authorizeIframeµ(url, config).pipe(
5793
Micro.flatMap((response) => {
94+
<<<<<<< HEAD
5895
if ('code' in response && 'state' in response) {
5996
log.debug('Received authorization code', response);
6097
return Micro.succeed(response as unknown as AuthorizeSuccessResponse);
6198
}
6299
log.error('Error in authorize response', response);
63100
const errorResponse = response as unknown as AuthorizeErrorResponse;
64101
return Micro.fail(createAuthorizeErrorµ(errorResponse, wellknown, config, options));
102+
=======
103+
return Micro.gen(function* () {
104+
if ('code' in response && 'state' in response) {
105+
log.debug('Received authorization code', response);
106+
return yield* Micro.succeed(response as unknown as AuthorizeSuccessResponse);
107+
}
108+
log.error('Error in authorize response', response);
109+
const errorResponse = response as { error: string; error_description: string };
110+
return yield* createAuthorizeErrorµ(errorResponse, wellknown, config, options);
111+
});
112+
>>>>>>> f35d74ad (feat(oidc-client): improve Effect usage)
65113
}),
66114
);
67115
}
68116
}),
69117
);
118+
<<<<<<< HEAD
119+
=======
120+
121+
return Micro.runPromiseExit(buildAuthorizeRequestµ);
122+
>>>>>>> f35d74ad (feat(oidc-client): improve Effect usage)
70123
}

0 commit comments

Comments
 (0)