Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/ebsi' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/callback-example/package.json
#	packages/client/lib/OpenID4VCIClient.ts
#	packages/client/package.json
#	packages/common/package.json
#	packages/issuer-rest/package.json
#	packages/issuer/package.json
#	pnpm-lock.yaml
  • Loading branch information
nklomp committed Jan 10, 2024
2 parents 6966e48 + 7eb9494 commit 459754f
Show file tree
Hide file tree
Showing 20 changed files with 316 additions and 61 deletions.
18 changes: 10 additions & 8 deletions packages/client/lib/AccessTokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export class AccessTokenClient {
public async acquireAccessToken(opts: AccessTokenRequestOpts): Promise<OpenIDResponse<AccessTokenResponse>> {
const { asOpts, pin, codeVerifier, code, redirectUri, metadata } = opts;

const credentialOffer = await assertedUniformCredentialOffer(opts.credentialOffer);
const isPinRequired = this.isPinRequiredValue(credentialOffer.credential_offer);
const issuer = getIssuerFromCredentialOfferPayload(credentialOffer.credential_offer) ?? (metadata?.issuer as string);
const credentialOffer = opts.credentialOffer ? await assertedUniformCredentialOffer(opts.credentialOffer) : undefined;
const isPinRequired = credentialOffer && this.isPinRequiredValue(credentialOffer.credential_offer);
const issuer =
opts.credentialIssuer ??
(credentialOffer ? getIssuerFromCredentialOfferPayload(credentialOffer.credential_offer) : (metadata?.issuer as string));
if (!issuer) {
throw Error('Issuer required at this point');
}
Expand Down Expand Up @@ -83,14 +85,14 @@ export class AccessTokenClient {

public async createAccessTokenRequest(opts: AccessTokenRequestOpts): Promise<AccessTokenRequest> {
const { asOpts, pin, codeVerifier, code, redirectUri } = opts;
const credentialOfferRequest = await toUniformCredentialOfferRequest(opts.credentialOffer);
const credentialOfferRequest = opts.credentialOffer ? await toUniformCredentialOfferRequest(opts.credentialOffer) : undefined;
const request: Partial<AccessTokenRequest> = {};

if (asOpts?.clientId) {
request.client_id = asOpts.clientId;
}

if (credentialOfferRequest.supportedFlows.includes(AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW)) {
if (credentialOfferRequest?.supportedFlows.includes(AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW)) {
this.assertNumericPin(this.isPinRequiredValue(credentialOfferRequest.credential_offer), pin);
request.user_pin = pin;

Expand All @@ -102,7 +104,7 @@ export class AccessTokenClient {
return request as AccessTokenRequest;
}

if (credentialOfferRequest.supportedFlows.includes(AuthzFlowType.AUTHORIZATION_CODE_FLOW)) {
if (!credentialOfferRequest || credentialOfferRequest.supportedFlows.includes(AuthzFlowType.AUTHORIZATION_CODE_FLOW)) {
request.grant_type = GrantTypes.AUTHORIZATION_CODE;
request.code = code;
request.redirect_uri = redirectUri;
Expand Down Expand Up @@ -243,7 +245,7 @@ export class AccessTokenClient {
}

private throwNotSupportedFlow(): void {
debug(`Only pre-authorized flow supported.`);
throw new Error('Only pre-authorized-code flow is supported');
debug(`Only pre-authorized or authorization code flows supported.`);
throw new Error('Only pre-authorized-code or authorization code flows are supported');
}
}
5 changes: 3 additions & 2 deletions packages/client/lib/CredentialRequestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ export class CredentialRequestClient {
throw new Error(URL_NOT_VALID);
}
debug(`Acquiring credential(s) from: ${credentialEndpoint}`);
debug(`request\n: ${JSON.stringify(request, null, 2)}`);
const requestToken: string = this.credentialRequestOpts.token;
const response: OpenIDResponse<CredentialResponse> = await post(credentialEndpoint, JSON.stringify(request), { bearerToken: requestToken });
debug(`Credential endpoint ${credentialEndpoint} response:\r\n${response}`);
debug(`Credential endpoint ${credentialEndpoint} response:\r\n${JSON.stringify(response, null, 2)}`);
return response;
}

Expand Down Expand Up @@ -99,7 +100,7 @@ export class CredentialRequestClient {
: await proofInput.build();

// TODO: we should move format specific logic
if (format === 'jwt_vc_json') {
if (format === 'jwt_vc_json' || format === 'jwt_vc') {
return {
types,
format,
Expand Down
19 changes: 19 additions & 0 deletions packages/client/lib/CredentialRequestClientBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ export class CredentialRequestClientBuilder {
token?: string;
version?: OpenId4VCIVersion;

public static fromCredentialIssuer({
credentialIssuer,
metadata,
version,
credentialTypes,
}: {
credentialIssuer: string;
metadata?: EndpointMetadata;
version?: OpenId4VCIVersion;
credentialTypes: string | string[];
}): CredentialRequestClientBuilder {
const issuer = credentialIssuer;
const builder = new CredentialRequestClientBuilder();
builder.withVersion(version ?? OpenId4VCIVersion.VER_1_0_11);
builder.withCredentialEndpoint(metadata?.credential_endpoint ?? (issuer.endsWith('/') ? `${issuer}credential` : `${issuer}/credential`));
builder.withCredentialType(credentialTypes);
return builder;
}

public static async fromURI({ uri, metadata }: { uri: string; metadata?: EndpointMetadata }): Promise<CredentialRequestClientBuilder> {
const offer = await CredentialOfferClient.fromURI(uri);
return CredentialRequestClientBuilder.fromCredentialOfferRequest({ request: offer, ...offer, metadata, version: offer.version });
Expand Down
Loading

0 comments on commit 459754f

Please sign in to comment.