Skip to content

Commit

Permalink
fix: relax auth_endpoint handling. Doesn't have to be available when …
Browse files Browse the repository at this point in the history
…doing pre-auth flow. Client handles errors anyway in case of auth/par flow
  • Loading branch information
nklomp committed Sep 28, 2023
1 parent 3c23bab commit cb5f9c1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/client/lib/MetadataClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class MetadataClient {
}
debug(`Issuer ${issuer} has ${authorizationServerType} Server metadata in well-known location`);
if (!authMetadata.authorization_endpoint) {
throw Error(`Authorization Sever ${authorization_server} did not provide an authorization_endpoint`);
console.warn(`Issuer ${issuer} of type ${authorizationServerType} has no authorization_endpoint! Will use ${authorization_endpoint}`);
} else if (authorization_endpoint && authMetadata.authorization_endpoint !== authorization_endpoint) {
throw Error(
`Credential issuer has a different authorization_endpoint (${authorization_endpoint}) from the Authorization Server (${authMetadata.authorization_endpoint})`,
Expand Down
45 changes: 45 additions & 0 deletions packages/client/lib/__tests__/MetadataClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,48 @@ describe('Metadataclient with Walt-id should', () => {
);
});
});

describe('Metadataclient with SpruceId should', () => {
beforeAll(() => {
nock.cleanAll();
});

afterEach(() => {
nock.cleanAll();
});
it('succeed without OID4VCI and with OIDC metadata', async () => {
/*nock(WALT_ISSUER_URL).get(WellKnownEndpoints.OPENID4VCI_ISSUER).reply(200, JSON.stringify(WALT_OID4VCI_METADATA));
nock(WALT_ISSUER_URL)
.get(/.well-known\/.*!/)
.times(2)
.reply(404, JSON.stringify({ error: 'does not exist' }));
*/
const metadata = await MetadataClient.retrieveAllMetadata('https://ngi-oidc4vci-test.spruceid.xyz');
expect(metadata.credential_endpoint).toEqual('https://ngi-oidc4vci-test.spruceid.xyz/credential');
expect(metadata.token_endpoint).toEqual('https://ngi-oidc4vci-test.spruceid.xyz/token');
expect(metadata.credentialIssuerMetadata).toEqual({
issuer: 'https://ngi-oidc4vci-test.spruceid.xyz',
credential_endpoint: 'https://ngi-oidc4vci-test.spruceid.xyz/credential',
token_endpoint: 'https://ngi-oidc4vci-test.spruceid.xyz/token',
jwks_uri: 'https://ngi-oidc4vci-test.spruceid.xyz/jwks',
grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],
credentials_supported: {
OpenBadgeCredential: {
formats: {
jwt_vc: {
types: ['VerifiableCredential', 'OpenBadgeCredential'],
cryptographic_binding_methods_supported: ['did'],
cryptographic_suites_supported: ['ES256', 'ES256K'],
},
ldp_vc: {
types: ['VerifiableCredential', 'OpenBadgeCredential'],
cryptographic_binding_methods_supported: ['did'],
cryptographic_suites_supported: ['Ed25519Signature2018'],
},
},
},
},
});
});
});
14 changes: 7 additions & 7 deletions packages/common/lib/functions/IssuerMetadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
IssuerMetadataV1_0_08,
MetadataDisplay,
OID4VCICredentialFormat,
OpenId4VCIVersion
} from '../types'
OpenId4VCIVersion,
} from '../types';

export function getSupportedCredentials(opts?: {
issuerMetadata?: CredentialIssuerMetadata | IssuerMetadataV1_0_08;
Expand Down Expand Up @@ -56,24 +56,24 @@ export function getSupportedCredential(opts?: {
/**
* the following (not array part is a legacy code from version 1_0-08 which JFF plugfest 2 implementors used)
*/
let initiationTypes :string[] | undefined
let initiationTypes: string[] | undefined;
if (opts?.types) {
if (typeof opts.types === 'string') {
initiationTypes = [opts.types]
initiationTypes = [opts.types];
} else {
initiationTypes = opts.types
initiationTypes = opts.types;
}
}
if (version === OpenId4VCIVersion.VER_1_0_08 && (!initiationTypes || initiationTypes?.length === 0)) {
initiationTypes = formats
initiationTypes = formats;
}
const supportedFormats: (CredentialOfferFormat | string)[] = formats && formats.length > 0 ? formats : ['jwt_vc_json', 'jwt_vc_json-ld', 'ldp_vc'];

const credentialSupportedOverlap: CredentialSupported[] = [];
if (opts?.types && typeof opts?.types === 'string') {
const supported = credentialsSupported.filter(
(sup) => sup.id === opts.types || (initiationTypes && arrayEqualsIgnoreOrder(sup.types, initiationTypes)),
)
);
if (supported) {
credentialSupportedOverlap.push(...supported);
}
Expand Down

0 comments on commit cb5f9c1

Please sign in to comment.