Skip to content

Commit

Permalink
fix: Merge conflict and changes
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Lanser <tom@devv.nl>
  • Loading branch information
Tommylans committed Nov 20, 2024
1 parent 8bb4564 commit f6f766d
Show file tree
Hide file tree
Showing 4 changed files with 351 additions and 530 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Key, getJwkFromKey, KeyType } from '@credo-ts/core'
import { createEntityConfiguration } from '@openid-federation/core'

import { getRequestContext, sendErrorResponse } from '../../shared/router'
import { OpenId4VcIssuerService } from '../OpenId4VcIssuerService'

// TODO: It's also possible that the issuer and the verifier can have the same openid-federation endpoint. In that case we need to combine them.

Expand All @@ -15,16 +14,13 @@ export function configureFederationEndpoint(router: Router) {

router.get('/.well-known/openid-federation', async (request: OpenId4VcIssuanceRequest, response: Response, next) => {
const { agentContext, issuer } = getRequestContext(request)
const openId4VcIssuerService = agentContext.dependencyManager.resolve(OpenId4VcIssuerService)

try {
// TODO: Should be only created once per issuer and be used between instances
const federationKey = await agentContext.wallet.createKey({
keyType: KeyType.Ed25519,
})

const issuerMetadata = openId4VcIssuerService.getIssuerMetadata(agentContext, issuer)

const now = new Date()
const expires = new Date(now.getTime() + 1000 * 60 * 60 * 24) // 1 day from now

Expand All @@ -35,14 +31,14 @@ export function configureFederationEndpoint(router: Router) {
const kid = federationKey.fingerprint
const alg = jwk.supportedSignatureAlgorithms[0]

const issuerDisplay = issuerMetadata.issuerDisplay?.[0]
const issuerDisplay = issuer.display?.[0]

const accessTokenSigningKey = Key.fromFingerprint(issuer.accessTokenPublicKeyFingerprint)

const entityConfiguration = await createEntityConfiguration({
claims: {
sub: issuerMetadata.issuerUrl,
iss: issuerMetadata.issuerUrl,
sub: issuer.issuerId,
iss: issuer.issuerId,
iat: now,
exp: expires,
jwks: {
Expand All @@ -52,7 +48,7 @@ export function configureFederationEndpoint(router: Router) {
federation_entity: issuerDisplay
? {
organization_name: issuerDisplay.name,
logo_uri: issuerDisplay.logo?.url,
logo_uri: issuerDisplay.logo?.uri,
}
: undefined,
openid_provider: {
Expand Down Expand Up @@ -99,7 +95,8 @@ export function configureFederationEndpoint(router: Router) {
agentContext.config.logger.error('Failed to create entity configuration', {
error,
})
sendErrorResponse(response, agentContext.config.logger, 500, 'invalid_request', error)
sendErrorResponse(response, next, agentContext.config.logger, 500, 'invalid_request', error)
return
}

// NOTE: if we don't call next, the agentContext session handler will NOT be called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function configureFederationEndpoint(router: Router) {
rpSigningKeyMapping.set(verifier.verifierId, rpSigningKey)
}

const relyingParty = await verifierService.getRelyingParty(agentContext, verifier.verifierId, {
const relyingParty = await verifierService.getRelyingParty(agentContext, verifier, {
clientId: verifierConfig.baseUrl,
clientIdScheme: 'entity_id',
authorizationResponseUrl: `${verifierConfig.baseUrl}/siop/${verifier.verifierId}/authorize`,
Expand Down Expand Up @@ -137,7 +137,8 @@ export function configureFederationEndpoint(router: Router) {
agentContext.config.logger.error('Failed to create entity configuration', {
error,
})
sendErrorResponse(response, agentContext.config.logger, 500, 'invalid_request', error)
sendErrorResponse(response, next, agentContext.config.logger, 500, 'invalid_request', error)
return
}

// NOTE: if we don't call next, the agentContext session handler will NOT be called
Expand Down
Loading

0 comments on commit f6f766d

Please sign in to comment.