Skip to content

Commit

Permalink
feat: added setDefaultTokenEndpoint to VcIssuerBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
sksadjad committed Jun 13, 2024
1 parent 9ea4709 commit 96608ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 0 additions & 8 deletions packages/issuer-rest/lib/oid4vci-api-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
ACCESS_TOKEN_ISSUER_REQUIRED_ERROR,
adjustUrl,
AuthorizationRequest,
CredentialIssuerMetadataOpts,
CredentialOfferRESTRequest,
CredentialRequestV1_0_11,
determineGrantTypes,
Expand Down Expand Up @@ -380,16 +379,9 @@ export function pushedAuthorizationEndpoint<DIDDoc extends object>(
})
}

function addTokenEndpoint(issuerMetadata: CredentialIssuerMetadataOpts) {
if (!issuerMetadata.token_endpoint) {
issuerMetadata.token_endpoint = `${issuerMetadata.credential_issuer}/token`
}
}

export function getMetadataEndpoint<DIDDoc extends object>(router: Router, issuer: VcIssuer<DIDDoc>) {
const path = `/.well-known/openid-credential-issuer`
router.get(path, (request: Request, response: Response) => {
addTokenEndpoint(issuer.issuerMetadata)
return response.send(issuer.issuerMetadata)
})
}
Expand Down
7 changes: 7 additions & 0 deletions packages/issuer/lib/builder/VcIssuerBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ export class VcIssuerBuilder<DIDDoc extends object> {
return this
}

private setDefaultTokenEndpoint(issuerMetadata: Partial<CredentialIssuerMetadata>) {
if (!issuerMetadata.token_endpoint) {
issuerMetadata.token_endpoint = `${issuerMetadata.credential_issuer}/token`
}
}

public build(): VcIssuer<DIDDoc> {
if (!this.credentialOfferStateManager) {
throw new Error(TokenErrorResponse.invalid_request)
Expand All @@ -155,6 +161,7 @@ export class VcIssuerBuilder<DIDDoc extends object> {

const builder = this.issuerMetadataBuilder?.build()
const metadata: Partial<CredentialIssuerMetadata> = { ...this.issuerMetadata, ...builder }
this.setDefaultTokenEndpoint(metadata)
// Let's make sure these get merged correctly:
metadata.credentials_supported = [...(this.issuerMetadata.credentials_supported ?? []), ...(builder?.credentials_supported ?? [])]
metadata.display = [...(this.issuerMetadata.display ?? []), ...(builder?.display ?? [])]
Expand Down

0 comments on commit 96608ec

Please sign in to comment.