eve-hub 0.13.1 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/hub-oidc.d.mts +1 -0
- package/hub-oidc.mjs +13 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/hub-oidc.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type TeamClaims = { iss: string; owner_id: string; project_id?: string; environment?: string; user_id?: string; exp: number; [claim: string]: unknown };
|
|
2
2
|
export function looksLikeJwt(token: string | null | undefined): boolean;
|
|
3
|
+
export function verifyIssuerToken(token: string, options: { iss: string; jwksUrl?: string; audience?: string; fetchImpl?: typeof fetch; now?: number }): Promise<Record<string, unknown> | undefined>;
|
|
3
4
|
export function verifyTeamToken(token: string, own: string, options?: { fetchImpl?: typeof fetch; now?: number; audience?: string }): Promise<TeamClaims | undefined>;
|
|
4
5
|
export function isHubRequest(request: Request, own: () => Promise<string>, options?: { env?: Record<string, string | undefined>; fetchImpl?: typeof fetch; now?: number }): Promise<boolean>;
|
package/hub-oidc.mjs
CHANGED
|
@@ -12,15 +12,26 @@ import { isBotToken } from "./bot-token.mjs";
|
|
|
12
12
|
const keySets = new WeakMap();
|
|
13
13
|
// Not a bad token but the keys that could not be read (a timeout, a non-200 answer, an unreadable key set): an outage, so it throws.
|
|
14
14
|
const KEY_FETCH_FAILED = new Set([errors.JWKSTimeout.code, errors.JWKSInvalid.code, errors.JOSEError.code]);
|
|
15
|
-
function keysOf(iss, fetchImpl) {
|
|
15
|
+
function keysOf(iss, fetchImpl, jwksUrl = `${iss}/.well-known/jwks.json`) {
|
|
16
16
|
if (!keySets.has(fetchImpl)) keySets.set(fetchImpl, new Map());
|
|
17
17
|
const sets = keySets.get(fetchImpl);
|
|
18
|
-
if (!sets.has(iss)) sets.set(iss, createRemoteJWKSet(new URL(
|
|
18
|
+
if (!sets.has(iss)) sets.set(iss, createRemoteJWKSet(new URL(jwksUrl), { [customFetch]: fetchImpl, cooldownDuration: 30_000, cacheMaxAge: 60 * 60_000 }));
|
|
19
19
|
return sets.get(iss);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export const looksLikeJwt = (token) => /^[\w-]+\.[\w-]+\.[\w-]*$/.test(String(token ?? ""));
|
|
23
23
|
|
|
24
|
+
/** The verified claims of `token` when `iss` (keys at `jwksUrl`) signed it for `audience`; undefined for any other token, a throw when the keys can't be read. */
|
|
25
|
+
export async function verifyIssuerToken(token, { iss, jwksUrl, audience, fetchImpl = fetch, now = Date.now() }) {
|
|
26
|
+
try {
|
|
27
|
+
const { payload } = await jwtVerify(token, keysOf(iss, fetchImpl, jwksUrl), { issuer: iss, audience, algorithms: ["RS256"], requiredClaims: ["exp"], currentDate: new Date(now) });
|
|
28
|
+
return payload;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (error instanceof errors.JOSEError && !KEY_FETCH_FAILED.has(error.code)) return undefined;
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
24
35
|
/**
|
|
25
36
|
* The verified claims of `token`, or undefined for any token that is not the checker's team's.
|
|
26
37
|
* `own` is the checker's own token (its `iss` and `owner_id` say which team to trust). With `audience`, the token's `aud` must be it.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eve-hub",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Bot-side code shared by every hub agent: registry tools, the roster hook, the eve channel, the host sandbox and browser, and model helpers.",
|
|
6
6
|
"type": "module",
|