2024-10-07 12:52:22 +02:00
|
|
|
import { auth } from "@/api";
|
2025-03-29 03:30:06 +01:00
|
|
|
import { describeRoute } from "hono-openapi";
|
|
|
|
|
import { resolver } from "hono-openapi/zod";
|
2024-10-07 12:52:22 +02:00
|
|
|
import { exportJWK } from "jose";
|
2025-03-29 03:30:06 +01:00
|
|
|
import { z } from "zod";
|
2024-10-07 12:52:22 +02:00
|
|
|
import type { PluginType } from "../index.ts";
|
|
|
|
|
|
2024-11-02 00:43:33 +01:00
|
|
|
export default (plugin: PluginType): void => {
|
2024-10-07 12:52:22 +02:00
|
|
|
plugin.registerRoute("/.well-known/jwks", (app) =>
|
2025-03-29 03:30:06 +01:00
|
|
|
app.get(
|
|
|
|
|
"/.well-known/jwks",
|
|
|
|
|
describeRoute({
|
2024-10-07 12:52:22 +02:00
|
|
|
summary: "JWK Set",
|
2025-03-28 22:12:07 +01:00
|
|
|
tags: ["OpenID"],
|
2024-10-07 12:52:22 +02:00
|
|
|
responses: {
|
|
|
|
|
200: {
|
|
|
|
|
description: "JWK Set",
|
|
|
|
|
content: {
|
|
|
|
|
"application/json": {
|
2025-03-29 03:30:06 +01:00
|
|
|
schema: resolver(
|
|
|
|
|
z.object({
|
|
|
|
|
keys: z.array(
|
|
|
|
|
z.object({
|
|
|
|
|
kty: z.string().optional(),
|
|
|
|
|
use: z.string(),
|
|
|
|
|
alg: z.string(),
|
|
|
|
|
kid: z.string(),
|
|
|
|
|
crv: z.string().optional(),
|
|
|
|
|
x: z.string().optional(),
|
|
|
|
|
y: z.string().optional(),
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
}),
|
|
|
|
|
),
|
2024-10-07 12:52:22 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
2025-03-29 03:30:06 +01:00
|
|
|
auth({
|
|
|
|
|
auth: false,
|
|
|
|
|
}),
|
|
|
|
|
plugin.middleware,
|
2024-10-07 12:52:22 +02:00
|
|
|
async (context) => {
|
|
|
|
|
const jwk = await exportJWK(
|
|
|
|
|
context.get("pluginConfig").keys?.public,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Remove the private key 💀
|
|
|
|
|
jwk.d = undefined;
|
|
|
|
|
|
|
|
|
|
return context.json(
|
|
|
|
|
{
|
|
|
|
|
keys: [
|
|
|
|
|
{
|
|
|
|
|
...jwk,
|
|
|
|
|
use: "sig",
|
|
|
|
|
alg: "EdDSA",
|
|
|
|
|
kid: "1",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
200,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
};
|