1- < < < << << HEAD
21/*
32 * Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
43 *
54 * This software may be modified and distributed under the terms
65 * of the MIT license. See the LICENSE file for details.
76 */
8- = === ===
9- >>> >>> > f35d74ad ( feat ( oidc - client ) : improve Effect usage )
107import { CustomLogger } from '@forgerock/sdk-logger' ;
118import { GetAuthorizationUrlOptions } from '@forgerock/sdk-oidc' ;
129import { Micro } from 'effect' ;
@@ -22,39 +19,18 @@ import {
2219import type { WellKnownResponse } from '@forgerock/sdk-types' ;
2320
2421import type { OidcConfig } from './config.types.js' ;
25- << << << < HEAD
2622import { AuthorizeErrorResponse , AuthorizeSuccessResponse } from './authorize.request.types.js' ;
27- === === =
28- import { AuthorizeSuccessResponse } from './authorize.request.types.js' ;
29- >>> >>> > f35d74ad ( feat ( oidc - client ) : improve Effect usage )
3023
3124export async function authorizeµ (
3225 wellknown : WellKnownResponse ,
3326 config : OidcConfig ,
3427 log : CustomLogger ,
3528 options ?: GetAuthorizationUrlOptions ,
3629) {
37- << << << < HEAD
3830 return buildAuthorizeOptionsµ ( wellknown , config , options ) . pipe (
3931 Micro . flatMap ( ( [ url , config , options ] ) => createAuthorizeUrlµ ( url , config , options ) ) ,
4032 Micro . tap ( ( url ) => log . debug ( 'Authorize URL created' , url ) ) ,
4133 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 )
5834 Micro . flatMap ( ( [ url , config , options ] ) => {
5935 if ( options . responseMode === 'pi.flow' ) {
6036 /**
@@ -63,61 +39,39 @@ export async function authorizeµ(
6339 * set iframe's to DENY.
6440 */
6541 return authorizeFetchµ ( url ) . pipe (
66- Micro . flatMap ( ( response ) => {
67- < < < << << HEAD
68- if ( 'authorizeResponse ' in response ) {
69- log . debug ( 'Received authorize response' , response . authorizeResponse ) ;
70- return Micro . succeed ( response . authorizeResponse ) ;
71- }
72- log . error ( 'Error in authorize response' , response ) ;
73- return Micro . fail ( createAuthorizeErrorµ ( response , wellknown , config , options ) ) ;
74- === = ===
75- return Micro . gen ( function * ( ) {
42+ Micro . flatMap (
43+ ( response ) : Micro . Micro < AuthorizeSuccessResponse , AuthorizeErrorResponse , never > => {
7644 if ( 'authorizeResponse' in response ) {
7745 log . debug ( 'Received authorize response' , response . authorizeResponse ) ;
78- return yield * Micro . succeed ( response . authorizeResponse as AuthorizeSuccessResponse ) ;
46+ return Micro . succeed ( response . authorizeResponse ) ;
7947 }
8048 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 )
85- } ) ,
49+ // For redirection, we need to remore `pi.flow` from the options
50+ const redirectOptions = options ;
51+ delete redirectOptions . responseMode ;
52+ return createAuthorizeErrorµ ( response , wellknown , config , options ) ;
53+ } ,
54+ ) ,
8655 ) ;
8756 } else {
8857 /**
8958 * If the response mode is not pi.flow, then we are likely using a traditional
9059 * redirect based server supporting iframes. An example would be PingAM.
9160 */
9261 return authorizeIframeµ ( url , config ) . pipe (
93- Micro . flatMap ( ( response ) => {
94- < < < << << HEAD
95- if ( 'code ' in response && 'state ' in response ) {
96- log . debug ( 'Received authorization code' , response ) ;
97- return Micro . succeed ( response as unknown as AuthorizeSuccessResponse ) ;
98- }
99- log . error ( 'Error in authorize response' , response ) ;
100- const errorResponse = response as unknown as AuthorizeErrorResponse ;
101- return Micro . fail ( createAuthorizeErrorµ ( errorResponse , wellknown , config , options ) ) ;
102- === = ===
103- return Micro . gen ( function * ( ) {
62+ Micro . flatMap (
63+ ( response ) : Micro . Micro < AuthorizeSuccessResponse , AuthorizeErrorResponse , never > => {
10464 if ( 'code' in response && 'state' in response ) {
10565 log . debug ( 'Received authorization code' , response ) ;
106- return yield * Micro . succeed ( response as unknown as AuthorizeSuccessResponse ) ;
66+ return Micro . succeed ( response as unknown as AuthorizeSuccessResponse ) ;
10767 }
10868 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 )
113- } ) ,
69+ const errorResponse = response as unknown as AuthorizeErrorResponse ;
70+ return createAuthorizeErrorµ ( errorResponse , wellknown , config , options ) ;
71+ } ,
72+ ) ,
11473 ) ;
11574 }
11675 } ) ,
11776 ) ;
118- << < < < << HEAD
119- === = ===
120-
121- return Micro . runPromiseExit ( buildAuthorizeRequestµ ) ;
122- >>> > >>> f35d74ad ( feat ( oidc - client ) : improve Effect usage )
12377}
0 commit comments