MCPcopy Create free account
hub / github.com/QuantiaAI/helm-agents / verifyAccessToken

Function verifyAccessToken

apps/api/src/auth/token.ts:27–49  ·  view source on GitHub ↗
(
  token: string,
  secret: string,
  now = nowSec(),
)

Source from the content-addressed store, hash-verified

25}
26
27export function verifyAccessToken(
28 token: string,
29 secret: string,
30 now = nowSec(),
31): AccessClaims | null {
32 const parts = token.split(".");
33 if (parts.length !== 3) return null;
34 const [h, b, s] = parts as [string, string, string];
35 const expected = b64(sig(`${h}.${b}`, secret));
36 const got = Buffer.from(s);
37 const exp = Buffer.from(expected);
38 if (got.length !== exp.length || !timingSafeEqual(got, exp)) return null;
39 let claims: AccessClaims;
40 try {
41 claims = JSON.parse(Buffer.from(b, "base64url").toString("utf8"));
42 } catch {
43 return null;
44 }
45 if (typeof claims.exp !== "number" || claims.exp < now || typeof claims.sub !== "string") {
46 return null;
47 }
48 return claims;
49}
50
51/** Opaque refresh token; only its hash is persisted. */
52export function generateRefreshToken(): { token: string; tokenHash: string } {

Callers 2

canActivateMethod · 0.85
token.spec.tsFile · 0.85

Calls 3

nowSecFunction · 0.85
b64Function · 0.85
sigFunction · 0.85

Tested by

no test coverage detected