Skip to content

Commit

Permalink
chore: investigate req opts not properly filled
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Jan 24, 2024
1 parent d95adbc commit 1390a43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 4 additions & 1 deletion packages/client/lib/AuthorizationCodeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const createAuthorizationRequestUrl = async ({
}),
authorization_details: JSON.stringify(handleAuthorizationDetails(endpointMetadata, authorizationDetails)),
redirect_uri: redirectUri,
scope: scope,
scope,
};

if (authorizationRequest.clientId) {
Expand All @@ -92,13 +92,16 @@ export const createAuthorizationRequestUrl = async ({
if (!parEndpoint && parMode === PARMode.REQUIRE) {
throw Error(`PAR mode is set to required by Authorization Server does not support PAR!`);
} else if (parEndpoint && parMode !== PARMode.NEVER) {
console.log(`USING PAR with endpoint ${parEndpoint}`);
const parResponse = await formPost<PushedAuthorizationResponse>(parEndpoint, new URLSearchParams(queryObj));
if (parResponse.errorBody || !parResponse.successBody) {
throw Error(`PAR error`);
}
console.log(`PAR response: ${(parResponse.successBody, null, 2)}`);
queryObj = { request_uri: parResponse.successBody.request_uri };
}

console.log(`QUERY obj: ` + JSON.stringify(queryObj, null, 2));
const url = convertJsonToURI(queryObj, {
baseUrl: endpointMetadata.authorization_endpoint,
uriTypeProperties: ['request_uri', 'redirect_uri', 'scope', 'authorization_details', 'issuer_state'],
Expand Down
10 changes: 4 additions & 6 deletions packages/client/lib/OpenID4VCIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class OpenID4VCIClient {
this._clientId = clientId ?? (credentialOffer ? getClientIdFromCredentialOfferPayload(credentialOffer.credential_offer) : undefined);
this._pkce = { ...this._pkce, ...pkce };
this._authorizationRequestOpts = this.syncAuthorizationRequestOpts(authorizationRequest);
console.log(`Authorization req options: ${JSON.stringify(this._authorizationRequestOpts, null, 2)}`);
}

public static async fromCredentialIssuer({
Expand Down Expand Up @@ -169,10 +170,7 @@ export class OpenID4VCIClient {

// todo: Probably can go with current logic in MetadataClient who will always set the authorization_endpoint when found
// handling this because of the support for v1_0-08
if (
this._endpointMetadata?.credentialIssuerMetadata &&
'authorization_endpoint' in this._endpointMetadata.credentialIssuerMetadata
) {
if (this._endpointMetadata?.credentialIssuerMetadata && 'authorization_endpoint' in this._endpointMetadata.credentialIssuerMetadata) {
this._endpointMetadata.authorization_endpoint = this._endpointMetadata.credentialIssuerMetadata.authorization_endpoint as string;
}
this._authorizationURL = await createAuthorizationRequestUrl({
Expand Down Expand Up @@ -519,9 +517,9 @@ export class OpenID4VCIClient {
private syncAuthorizationRequestOpts(opts?: AuthorizationRequestOpts): AuthorizationRequestOpts {
let authorizationRequestOpts = { ...this._authorizationRequestOpts, ...opts } as AuthorizationRequestOpts;
if (!authorizationRequestOpts) {
authorizationRequestOpts = { redirectUri: 'openid4vc%3A' }
authorizationRequestOpts = { redirectUri: 'openid4vc%3A' };
}
const clientId = authorizationRequestOpts.clientId ?? this._clientId
const clientId = authorizationRequestOpts.clientId ?? this._clientId;
this._clientId = clientId;
authorizationRequestOpts.clientId = clientId;

Expand Down

0 comments on commit 1390a43

Please sign in to comment.