Skip to content

Commit 7a1afbc

Browse files
committed
fix: Do not set default client_id
1 parent 846229a commit 7a1afbc

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

packages/client/lib/OpenID4VCIClient.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ export class OpenID4VCIClient {
7676
this._kid = kid;
7777
this._alg = alg;
7878
// TODO: We need to refactor this and always explicitly call createAuthorizationRequestUrl, so we can have a credential selection first and use the kid as a default for the client id
79-
this._clientId =
80-
clientId ??
81-
(credentialOffer && getClientIdFromCredentialOfferPayload(credentialOffer.credential_offer)) ??
82-
kid?.split('#')[0] ??
83-
'com.sphereon.ssi.wallet';
79+
this._clientId = clientId ?? (credentialOffer && getClientIdFromCredentialOfferPayload(credentialOffer.credential_offer)) ?? kid?.split('#')[0];
8480
this._pkce = { ...this._pkce, ...pkce };
8581
this._authorizationRequestOpts = this.syncAuthorizationRequestOpts(authorizationRequest);
8682
debug(`Authorization req options: ${JSON.stringify(this._authorizationRequestOpts, null, 2)}`);
@@ -208,6 +204,7 @@ export class OpenID4VCIClient {
208204
throw Error(`Cannot retrieve issuer metadata without either a credential offer, or issuer value`);
209205
}
210206
}
207+
211208
return this.endpointMetadata;
212209
}
213210

@@ -530,6 +527,24 @@ export class OpenID4VCIClient {
530527
return this.endpointMetadata ? this.endpointMetadata.credential_endpoint : `${this.getIssuer()}/credential`;
531528
}
532529

530+
/**
531+
* Too bad we need a method like this, but EBSI is not exposing metadata
532+
*/
533+
public isEBSI() {
534+
if (
535+
this.credentialOffer?.credential_offer.credentials.find(
536+
(cred) =>
537+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
538+
// @ts-ignore
539+
typeof cred !== 'string' && 'trust_framework' in cred && 'name' in cred.trust_framework && cred.trust_framework.name.includes('ebsi'),
540+
)
541+
) {
542+
return true;
543+
}
544+
this.assertIssuerData();
545+
return this.endpointMetadata.credentialIssuerMetadata?.authorization_endpoint?.includes('ebsi.eu');
546+
}
547+
533548
private assertIssuerData(): void {
534549
if (!this._credentialIssuer) {
535550
throw Error(`No credential issuer value present`);

packages/common/lib/functions/CredentialRequestUtil.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export function getTypesFromRequest(credentialRequest: UniformCredentialRequest,
1111
// @ts-ignore
1212
types =
1313
'credential_definition' in credentialRequest && credentialRequest.credential_definition
14-
? credentialRequest.credential_definition.types
14+
? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
15+
// @ts-ignore
16+
credentialRequest.credential_definition.types
1517
: credentialRequest.types;
1618
} else if (credentialRequest.format === 'vc+sd-jwt') {
1719
types = [credentialRequest.vct];

packages/common/lib/functions/IssuerMetadataUtils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
AuthorizationServerMetadata,
23
CredentialIssuerMetadata,
34
CredentialOfferFormat,
45
CredentialSupported,
@@ -165,3 +166,21 @@ export function getIssuerDisplays(metadata: CredentialIssuerMetadata | IssuerMet
165166
) ?? [];
166167
return matchedDisplays.sort((item) => (item.locale ? opts?.prefLocales.indexOf(item.locale) ?? 1 : Number.MAX_VALUE));
167168
}
169+
170+
/**
171+
* TODO check again when WAL-617 is done to replace how we get the issuer name.
172+
*/
173+
export function getIssuerName(
174+
url: string,
175+
credentialIssuerMetadata?: Partial<AuthorizationServerMetadata> & (CredentialIssuerMetadata | IssuerMetadataV1_0_08),
176+
): string {
177+
if (credentialIssuerMetadata) {
178+
const displays: Array<MetadataDisplay> = credentialIssuerMetadata ? getIssuerDisplays(credentialIssuerMetadata) : [];
179+
for (const display of displays) {
180+
if (display.name) {
181+
return display.name;
182+
}
183+
}
184+
}
185+
return url;
186+
}

0 commit comments

Comments
 (0)