-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: OpenID Federation for the verifier <-> holder #27
Changes from 3 commits
b723485
bcaed4d
1743fb1
dcd810d
cb6d70f
b06c546
06999df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import type { OpenId4VcIssuanceRequest } from './requestContext' | ||
import type { FederationKeyCallback } from '../../shared/federation' | ||
import type { Buffer } from '@credo-ts/core' | ||
import type { Router, Response } from 'express' | ||
|
||
import { getJwkFromKey } from '@credo-ts/core' | ||
import { createEntityConfiguration } from '@openid-federation/core' | ||
|
||
import { getRequestContext, sendErrorResponse } from '../../shared/router' | ||
import { OpenId4VcIssuerService } from '../OpenId4VcIssuerService' | ||
|
||
export interface OpenId4VcSiopFederationEndpointConfig { | ||
/** | ||
* The path at which the credential endpoint should be made available. Note that it will be | ||
* hosted at a subpath to take into account multiple tenants and issuers. | ||
* | ||
* @default /.well-known/openid-federation | ||
*/ | ||
endpointPath: string | ||
|
||
// TODO: Not sure about the property name yet. | ||
//TODO: More information is needed than only the key also the client id etc | ||
keyCallback: FederationKeyCallback<{ | ||
issuerId: string | ||
}> | ||
} | ||
|
||
// 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. | ||
|
||
export function configureFederationEndpoint(router: Router, config: OpenId4VcSiopFederationEndpointConfig) { | ||
router.get(config.endpointPath, async (request: OpenId4VcIssuanceRequest, response: Response, next) => { | ||
const { agentContext, issuer } = getRequestContext(request) | ||
const openId4VcIssuerService = agentContext.dependencyManager.resolve(OpenId4VcIssuerService) | ||
|
||
try { | ||
const issuerMetadata = openId4VcIssuerService.getIssuerMetadata(agentContext, issuer) | ||
// TODO: Use a type here from sphreon | ||
const transformedMetadata = { | ||
Tommylans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
credential_issuer: issuerMetadata.issuerUrl, | ||
token_endpoint: issuerMetadata.tokenEndpoint, | ||
credential_endpoint: issuerMetadata.credentialEndpoint, | ||
authorization_server: issuerMetadata.authorizationServer, | ||
authorization_servers: issuerMetadata.authorizationServer ? [issuerMetadata.authorizationServer] : undefined, | ||
credentials_supported: issuerMetadata.credentialsSupported, | ||
credential_configurations_supported: issuerMetadata.credentialConfigurationsSupported, | ||
display: issuerMetadata.issuerDisplay, | ||
dpop_signing_alg_values_supported: issuerMetadata.dpopSigningAlgValuesSupported, | ||
} as const | ||
|
||
const now = new Date() | ||
const expires = new Date(now.getTime() + 1000 * 60 * 60 * 24) // 1 day from now | ||
|
||
const { key } = await config.keyCallback(agentContext, { | ||
issuerId: issuer.issuerId, | ||
}) | ||
|
||
const jwk = getJwkFromKey(key) | ||
const kid = 'key-1' | ||
const alg = jwk.supportedSignatureAlgorithms[0] | ||
|
||
const issuerDisplay = issuerMetadata.issuerDisplay?.[0] | ||
|
||
const entityConfiguration = await createEntityConfiguration({ | ||
claims: { | ||
sub: issuerMetadata.issuerUrl, | ||
iss: issuerMetadata.issuerUrl, | ||
iat: now, | ||
exp: expires, | ||
jwks: { | ||
keys: [{ kid, alg, ...jwk.toJson() }], | ||
}, | ||
metadata: { | ||
federation_entity: issuerDisplay | ||
? { | ||
organization_name: issuerDisplay.organization_name, | ||
logo_uri: issuerDisplay.logo_uri, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. organization_name and logo_uri are different in te issuer display. I think |
||
} | ||
: undefined, | ||
openid_credential_issuer: transformedMetadata, | ||
}, | ||
}, | ||
header: { | ||
kid, | ||
alg, | ||
typ: 'entity-statement+jwt', | ||
}, | ||
signJwtCallback: ({ toBeSigned }) => | ||
agentContext.wallet.sign({ | ||
data: toBeSigned as Buffer, | ||
key, | ||
}), | ||
}) | ||
|
||
response.writeHead(200, { 'Content-Type': 'application/entity-statement+jwt' }).end(entityConfiguration) | ||
} catch (error) { | ||
sendErrorResponse(response, agentContext.config.logger, 500, 'invalid_request', error) | ||
} | ||
|
||
// NOTE: if we don't call next, the agentContext session handler will NOT be called | ||
next() | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import type { OpenId4VcSiopAuthorizationEndpointConfig } from './router/authorizationEndpoint' | ||
import type { OpenId4VcSiopAuthorizationRequestEndpointConfig } from './router/authorizationRequestEndpoint' | ||
import type { OpenId4VcSiopFederationEndpointConfig } from './router/federationEndpoint' | ||
import type { Optional } from '@credo-ts/core' | ||
import type { Router } from 'express' | ||
|
||
|
@@ -24,6 +25,7 @@ export interface OpenId4VcVerifierModuleConfigOptions { | |
endpoints?: { | ||
authorization?: Optional<OpenId4VcSiopAuthorizationEndpointConfig, 'endpointPath'> | ||
authorizationRequest?: Optional<OpenId4VcSiopAuthorizationRequestEndpointConfig, 'endpointPath'> | ||
federation?: Optional<OpenId4VcSiopFederationEndpointConfig, 'endpointPath'> | ||
} | ||
} | ||
|
||
|
@@ -60,4 +62,15 @@ export class OpenId4VcVerifierModuleConfig { | |
endpointPath: userOptions?.endpointPath ?? '/authorize', | ||
} | ||
} | ||
|
||
public get federationEndpoint(): OpenId4VcSiopFederationEndpointConfig | undefined { | ||
// Use user supplied options, or return defaults. | ||
const userOptions = this.options.endpoints?.federation | ||
if (!userOptions) return undefined | ||
|
||
return { | ||
...userOptions, | ||
endpointPath: userOptions.endpointPath ?? '/.well-known/openid-federation', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. always well-known, not configurable |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ok for now, but was also discussing with NF and i think we probably need to have some more control over 'trusted' entities in Credo.
So extend the x509 callbacks with global 'verificationContext` and you can either provide it to the call, or we use the global static config, or we use the dynamic callback. And you can either provide trusted federations, trusted x509s, or trusted dids / did methods.
(just rambling here 😄 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we should think a bit more about this of what a good structure would be.