@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 21 lines 697 Bytes
Raw
1 import { createRemoteJWKSet, jwtVerify } from "jose";
2
3 export function makeAuthenticate(baseUrl: string, jwksUrl: string) {
4 const jwks = createRemoteJWKSet(new URL(jwksUrl));
5 const issuer = new URL(baseUrl).origin;
6 return async (authorization: string | null): Promise<string | undefined> => {
7 if (!authorization?.toLowerCase().startsWith("bearer ")) return;
8 try {
9 const { payload } = await jwtVerify(authorization.slice(7), jwks, {
10 issuer,
11 audience: issuer,
12 algorithms: ["EdDSA"],
13 requiredClaims: ["sub", "exp", "iat"],
14 maxTokenAge: "15 minutes",
15 });
16 return payload.sub || undefined;
17 } catch {
18 return;
19 }
20 };
21 }