mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Fix JWKS endpoint headers
Some checks failed
all-good: Did all the other checks pass? / all-good (push) Has been cancelled
Ensure Prisma migrations are in sync with the schema / check_prisma_migrations (22.x) (push) Has been cancelled
Docker Emulator Test / docker (push) Has been cancelled
Docker Server Build and Push / Docker Build and Push Server (push) Has been cancelled
Docker Server Test / docker (push) Has been cancelled
Runs E2E API Tests / build (22.x) (push) Has been cancelled
Runs E2E API Tests with external source of truth / build (22.x) (push) Has been cancelled
Lint & build / lint_and_build (latest) (push) Has been cancelled
Dev Environment Test / restart-dev-and-test (push) Has been cancelled
Run setup tests / setup-tests (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled
Mirror main branch to main-mirror-for-wdb / lint_and_build (push) Has been cancelled
Sync Main to Dev / sync-commits (push) Has been cancelled
Some checks failed
all-good: Did all the other checks pass? / all-good (push) Has been cancelled
Ensure Prisma migrations are in sync with the schema / check_prisma_migrations (22.x) (push) Has been cancelled
Docker Emulator Test / docker (push) Has been cancelled
Docker Server Build and Push / Docker Build and Push Server (push) Has been cancelled
Docker Server Test / docker (push) Has been cancelled
Runs E2E API Tests / build (22.x) (push) Has been cancelled
Runs E2E API Tests with external source of truth / build (22.x) (push) Has been cancelled
Lint & build / lint_and_build (latest) (push) Has been cancelled
Dev Environment Test / restart-dev-and-test (push) Has been cancelled
Run setup tests / setup-tests (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled
Mirror main branch to main-mirror-for-wdb / lint_and_build (push) Has been cancelled
Sync Main to Dev / sync-commits (push) Has been cancelled
This commit is contained in:
parent
677bba3486
commit
bbba9f1a65
@ -1,4 +1,4 @@
|
||||
import { yupArray, yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields";
|
||||
import { yupArray, yupNumber, yupObject, yupString, yupTuple } from "@stackframe/stack-shared/dist/schema-fields";
|
||||
import { StatusError } from "@stackframe/stack-shared/dist/utils/errors";
|
||||
import { deindent } from "@stackframe/stack-shared/dist/utils/strings";
|
||||
import { getProject } from "../../../../../../../lib/projects";
|
||||
@ -27,7 +27,9 @@ export const GET = createSmartRouteHandler({
|
||||
body: yupObject({
|
||||
keys: yupArray().defined(),
|
||||
}).defined(),
|
||||
|
||||
headers: yupObject({
|
||||
"Cache-Control": yupTuple([yupString().defined()]).defined(),
|
||||
}).defined(),
|
||||
}),
|
||||
async handler({ params, query }) {
|
||||
const project = await getProject(params.project_id);
|
||||
@ -42,7 +44,7 @@ export const GET = createSmartRouteHandler({
|
||||
body: await getPublicProjectJwkSet(params.project_id, query.include_anonymous === "true"),
|
||||
headers: {
|
||||
// Cache for 1 hour
|
||||
"Cache-Control": "public, max-age=3600",
|
||||
"Cache-Control": ["public, max-age=3600"] as const,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@ -122,16 +122,16 @@ export async function createResponse<T extends SmartResponse>(req: NextRequest |
|
||||
headers.set("x-stack-actual-status", [obj.statusCode.toString()]);
|
||||
}
|
||||
|
||||
// set all headers from the smart response (considering case insensitivity)
|
||||
for (const [key, values] of Object.entries(obj.headers ?? {})) {
|
||||
headers.set(key.toLowerCase(), values);
|
||||
}
|
||||
|
||||
return new Response(
|
||||
arrayBufferBody,
|
||||
{
|
||||
status,
|
||||
headers: [
|
||||
...Object.entries({
|
||||
...Object.fromEntries(headers),
|
||||
...obj.headers ?? {}
|
||||
}).flatMap(([key, values]) => values.map(v => [key.toLowerCase(), v!] as [string, string])),
|
||||
],
|
||||
headers: [...headers].flatMap(([key, values]) => values.map(v => [key, v] satisfies [string, string])),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@ -1477,6 +1477,7 @@ it("has a correctly formatted JWKS endpoint", async ({ expect }) => {
|
||||
const response = await niceBackendFetch("/api/v1/projects/internal/.well-known/jwks.json");
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.headers.get("content-type")).includes("application/json");
|
||||
expect(response.headers.get("cache-control")).toBe("public, max-age=3600");
|
||||
expect(response.body).toEqual({
|
||||
keys: [
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user