Skip to content

Commit

Permalink
feat: JWKS hosting for all keys when Sphereon Key Manager is used
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Oct 24, 2024
1 parent 578d62e commit 1cac215
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/public-key-hosting/src/api-functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'
import { ISphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager'
import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'
import { Request, Response, Router } from 'express'
import { JKWS_HOSTING_ALL_KEYS_PATH, JWKS_HOSTING_DID_KEYS_PATH } from './environment'
import { toJWKS } from './functions'
Expand All @@ -15,8 +17,12 @@ export function getAllJWKSEndpoint(router: Router, context: IRequiredContext, op
logger.info(`All JWKS endpoint enabled, path ${path}`)
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
try {
if (!contextHasPlugin<ISphereonKeyManager>(context, 'keyManagerListKeys')) {
return sendErrorResponse(response, 500, 'Key manager plugin that can list keys is not found. Please enable the Sphereon Key Manager plugin if you want to use this endpoint')
}
response.statusCode = 202
return response.send({})
const keys = await context.agent.keyManagerListKeys()
return response.send(toJWKS({ keys }))
} catch (e) {
return sendErrorResponse(response, 500, e.message as string, e)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/public-key-hosting/src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const JKWS_HOSTING_ALL_KEYS_PATH = process.env.JWKS_HOSTING_BASE_PATH ?? '/.well-known/jwks.json'
export const JWKS_HOSTING_DID_KEYS_PATH = process.env.JWKS_HOSTING_BASE_PATH ?? '/.well-known/jwks/dids/:did'
export const JWKS_HOSTING_DID_KEYS_PATH = process.env.JWKS_HOSTING_DID_PATH ?? '/.well-known/jwks/dids/:did'

0 comments on commit 1cac215

Please sign in to comment.