Skip to content

Commit 78abccf

Browse files
committed
chore: PAR fixes
1 parent 9f0679e commit 78abccf

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

packages/client/lib/AuthorizationCodeClient.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import {
66
CredentialOfferRequestWithBaseUrl,
77
CredentialSupported,
88
EndpointMetadataResult,
9+
formPost,
910
JsonURIMode,
1011
PARMode,
1112
PKCEOpts,
1213
PushedAuthorizationResponse,
1314
ResponseType,
1415
} from '@sphereon/oid4vci-common';
15-
import { formPost } from '@sphereon/oid4vci-common';
1616
import Debug from 'debug';
1717

1818
const debug = Debug('sphereon:oid4vci');
@@ -91,12 +91,24 @@ export const createAuthorizationRequestUrl = async ({
9191
throw Error(`PAR mode is set to required by Authorization Server does not support PAR!`);
9292
} else if (parEndpoint && parMode !== PARMode.NEVER) {
9393
debug(`USING PAR with endpoint ${parEndpoint}`);
94-
const parResponse = await formPost<PushedAuthorizationResponse>(parEndpoint, new URLSearchParams(queryObj));
94+
const parResponse = await formPost<PushedAuthorizationResponse>(
95+
parEndpoint,
96+
convertJsonToURI(queryObj, {
97+
mode: JsonURIMode.X_FORM_WWW_URLENCODED,
98+
uriTypeProperties: ['client_id', 'request_uri', 'redirect_uri', 'scope', 'authorization_details', 'issuer_state'],
99+
}),
100+
{ contentType: 'application/x-www-form-urlencoded', accept: 'application/json' },
101+
);
95102
if (parResponse.errorBody || !parResponse.successBody) {
96-
throw Error(`PAR error`);
103+
console.log(JSON.stringify(parResponse.errorBody));
104+
console.log('Falling back to regular request URI, since PAR failed');
105+
if (parMode === PARMode.REQUIRE) {
106+
throw Error(`PAR error: ${parResponse.origResponse.statusText}`);
107+
}
108+
} else {
109+
debug(`PAR response: ${(parResponse.successBody, null, 2)}`);
110+
queryObj = { request_uri: parResponse.successBody.request_uri };
97111
}
98-
debug(`PAR response: ${(parResponse.successBody, null, 2)}`);
99-
queryObj = { request_uri: parResponse.successBody.request_uri };
100112
}
101113

102114
debug(`Object that will become query params: ` + JSON.stringify(queryObj, null, 2));

0 commit comments

Comments
 (0)