@blimu/backend 1.1.4 → 1.2.0
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/dist/client-B-ZYoU15.d.mts +95 -0
- package/dist/client-GKBT3WCg.d.ts +95 -0
- package/dist/client.d.mts +1 -30
- package/dist/client.d.ts +1 -30
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +469 -13
- package/dist/index.d.ts +469 -13
- package/package.json +2 -2
- package/dist/__tests__/token-verifier.test.cjs +0 -17662
- package/dist/__tests__/token-verifier.test.cjs.map +0 -1
- package/dist/__tests__/token-verifier.test.d.mts +0 -2
- package/dist/__tests__/token-verifier.test.d.ts +0 -2
- package/dist/__tests__/token-verifier.test.mjs +0 -17661
- package/dist/__tests__/token-verifier.test.mjs.map +0 -1
- package/dist/auth-strategies.cjs +0 -42
- package/dist/auth-strategies.cjs.map +0 -1
- package/dist/auth-strategies.d.mts +0 -16
- package/dist/auth-strategies.d.ts +0 -16
- package/dist/auth-strategies.mjs +0 -17
- package/dist/auth-strategies.mjs.map +0 -1
- package/dist/schema.zod-DtXVS-1g.d.mts +0 -434
- package/dist/schema.zod-DtXVS-1g.d.ts +0 -434
- package/dist/schema.zod.cjs +0 -489
- package/dist/schema.zod.cjs.map +0 -1
- package/dist/schema.zod.d.mts +0 -2
- package/dist/schema.zod.d.ts +0 -2
- package/dist/schema.zod.mjs +0 -427
- package/dist/schema.zod.mjs.map +0 -1
- package/dist/services/bulk_resources.cjs +0 -48
- package/dist/services/bulk_resources.cjs.map +0 -1
- package/dist/services/bulk_resources.d.mts +0 -10
- package/dist/services/bulk_resources.d.ts +0 -10
- package/dist/services/bulk_resources.mjs +0 -23
- package/dist/services/bulk_resources.mjs.map +0 -1
- package/dist/services/bulk_roles.cjs +0 -48
- package/dist/services/bulk_roles.cjs.map +0 -1
- package/dist/services/bulk_roles.d.mts +0 -10
- package/dist/services/bulk_roles.d.ts +0 -10
- package/dist/services/bulk_roles.mjs +0 -23
- package/dist/services/bulk_roles.mjs.map +0 -1
- package/dist/services/entitlements.cjs +0 -72
- package/dist/services/entitlements.cjs.map +0 -1
- package/dist/services/entitlements.d.mts +0 -12
- package/dist/services/entitlements.d.ts +0 -12
- package/dist/services/entitlements.mjs +0 -47
- package/dist/services/entitlements.mjs.map +0 -1
- package/dist/services/plans.cjs +0 -70
- package/dist/services/plans.cjs.map +0 -1
- package/dist/services/plans.d.mts +0 -12
- package/dist/services/plans.d.ts +0 -12
- package/dist/services/plans.mjs +0 -45
- package/dist/services/plans.mjs.map +0 -1
- package/dist/services/resource_members.cjs +0 -48
- package/dist/services/resource_members.cjs.map +0 -1
- package/dist/services/resource_members.d.mts +0 -10
- package/dist/services/resource_members.d.ts +0 -10
- package/dist/services/resource_members.mjs +0 -23
- package/dist/services/resource_members.mjs.map +0 -1
- package/dist/services/resources.cjs +0 -94
- package/dist/services/resources.cjs.map +0 -1
- package/dist/services/resources.d.mts +0 -14
- package/dist/services/resources.d.ts +0 -14
- package/dist/services/resources.mjs +0 -69
- package/dist/services/resources.mjs.map +0 -1
- package/dist/services/roles.cjs +0 -71
- package/dist/services/roles.cjs.map +0 -1
- package/dist/services/roles.d.mts +0 -12
- package/dist/services/roles.d.ts +0 -12
- package/dist/services/roles.mjs +0 -46
- package/dist/services/roles.mjs.map +0 -1
- package/dist/services/usage.cjs +0 -96
- package/dist/services/usage.cjs.map +0 -1
- package/dist/services/usage.d.mts +0 -14
- package/dist/services/usage.d.ts +0 -14
- package/dist/services/usage.mjs +0 -71
- package/dist/services/usage.mjs.map +0 -1
- package/dist/services/users.cjs +0 -105
- package/dist/services/users.cjs.map +0 -1
- package/dist/services/users.d.mts +0 -15
- package/dist/services/users.d.ts +0 -15
- package/dist/services/users.mjs +0 -80
- package/dist/services/users.mjs.map +0 -1
- package/dist/token-verifier.cjs +0 -218
- package/dist/token-verifier.cjs.map +0 -1
- package/dist/token-verifier.d.mts +0 -35
- package/dist/token-verifier.d.ts +0 -35
- package/dist/token-verifier.mjs +0 -180
- package/dist/token-verifier.mjs.map +0 -1
package/dist/services/users.mjs
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// src/services/users.ts
|
|
2
|
-
import "@blimu/fetch";
|
|
3
|
-
var UsersService = class {
|
|
4
|
-
constructor(core) {
|
|
5
|
-
this.core = core;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* GET /v1/users*
|
|
9
|
-
* @summary List users*
|
|
10
|
-
* @description Retrieves a paginated list of users in your environment. Supports search functionality to filter users by email, name, or lookup key.*/
|
|
11
|
-
list(query, init) {
|
|
12
|
-
return this.core.request({
|
|
13
|
-
method: "GET",
|
|
14
|
-
path: `/v1/users`,
|
|
15
|
-
query,
|
|
16
|
-
...init ?? {}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* POST /v1/users*
|
|
21
|
-
* @summary Create a user*
|
|
22
|
-
* @description Creates a new user in your environment. The lookupKey is a unique identifier that you can use to reference the user in your system. It should be stable and not change over time.*/
|
|
23
|
-
create(body, init) {
|
|
24
|
-
return this.core.request({
|
|
25
|
-
method: "POST",
|
|
26
|
-
path: `/v1/users`,
|
|
27
|
-
body,
|
|
28
|
-
...init ?? {}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* DELETE /v1/users/{userId}*
|
|
33
|
-
* @summary Delete a user*
|
|
34
|
-
* @description Deletes a user by their ID or lookup key. This operation is permanent and cannot be undone. Deleting a user will also remove all role assignments for that user.*/
|
|
35
|
-
delete(userId, init) {
|
|
36
|
-
return this.core.request({
|
|
37
|
-
method: "DELETE",
|
|
38
|
-
path: `/v1/users/${encodeURIComponent(userId)}`,
|
|
39
|
-
...init ?? {}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* GET /v1/users/{userId}*
|
|
44
|
-
* @summary Get a user by ID*
|
|
45
|
-
* @description Retrieves a single user by their ID or lookup key. Returns user information including email, name, and metadata.*/
|
|
46
|
-
read(userId, init) {
|
|
47
|
-
return this.core.request({
|
|
48
|
-
method: "GET",
|
|
49
|
-
path: `/v1/users/${encodeURIComponent(userId)}`,
|
|
50
|
-
...init ?? {}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* PUT /v1/users/{userId}*
|
|
55
|
-
* @summary Update a user*
|
|
56
|
-
* @description Updates an existing user. You can modify email, name, and other user properties. The lookupKey can be updated but should remain stable.*/
|
|
57
|
-
update(userId, body, init) {
|
|
58
|
-
return this.core.request({
|
|
59
|
-
method: "PUT",
|
|
60
|
-
path: `/v1/users/${encodeURIComponent(userId)}`,
|
|
61
|
-
body,
|
|
62
|
-
...init ?? {}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* GET /v1/users/{userId}/effective-user-resources-roles*
|
|
67
|
-
* @summary List effective user resources roles*
|
|
68
|
-
* @description Retrieves all resources and roles for a user, including inherited roles from parent resources. The response indicates whether each role is directly assigned or inherited through resource hierarchies.*/
|
|
69
|
-
listEffectiveUserResourcesRoles(userId, init) {
|
|
70
|
-
return this.core.request({
|
|
71
|
-
method: "GET",
|
|
72
|
-
path: `/v1/users/${encodeURIComponent(userId)}/effective-user-resources-roles`,
|
|
73
|
-
...init ?? {}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
export {
|
|
78
|
-
UsersService
|
|
79
|
-
};
|
|
80
|
-
//# sourceMappingURL=users.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/services/users.ts"],"sourcesContent":["import { FetchClient } from '@blimu/fetch';\nimport * as Schema from '../schema';\n\nexport class UsersService {\n constructor(private core: FetchClient) {}\n\n /**\n * GET /v1/users*\n * @summary List users*\n * @description Retrieves a paginated list of users in your environment. Supports search functionality to filter users by email, name, or lookup key.*/\n list(\n query?: Schema.UsersListQuery,\n init?: Omit<RequestInit, 'method' | 'body'>\n ): Promise<Schema.UserList> {\n return this.core.request({\n method: 'GET',\n path: `/v1/users`,\n query,\n ...(init ?? {}),\n });\n }\n\n /**\n * POST /v1/users*\n * @summary Create a user*\n * @description Creates a new user in your environment. The lookupKey is a unique identifier that you can use to reference the user in your system. It should be stable and not change over time.*/\n create(\n body: Schema.UserCreateBody,\n init?: Omit<RequestInit, 'method' | 'body'>\n ): Promise<Schema.User> {\n return this.core.request({\n method: 'POST',\n path: `/v1/users`,\n body,\n ...(init ?? {}),\n });\n }\n\n /**\n * DELETE /v1/users/{userId}*\n * @summary Delete a user*\n * @description Deletes a user by their ID or lookup key. This operation is permanent and cannot be undone. Deleting a user will also remove all role assignments for that user.*/\n delete(userId: string, init?: Omit<RequestInit, 'method' | 'body'>): Promise<unknown> {\n return this.core.request({\n method: 'DELETE',\n path: `/v1/users/${encodeURIComponent(userId)}`,\n ...(init ?? {}),\n });\n }\n\n /**\n * GET /v1/users/{userId}*\n * @summary Get a user by ID*\n * @description Retrieves a single user by their ID or lookup key. Returns user information including email, name, and metadata.*/\n read(userId: string, init?: Omit<RequestInit, 'method' | 'body'>): Promise<Schema.User> {\n return this.core.request({\n method: 'GET',\n path: `/v1/users/${encodeURIComponent(userId)}`,\n ...(init ?? {}),\n });\n }\n\n /**\n * PUT /v1/users/{userId}*\n * @summary Update a user*\n * @description Updates an existing user. You can modify email, name, and other user properties. The lookupKey can be updated but should remain stable.*/\n update(\n userId: string,\n body: Schema.UserUpdateBody,\n init?: Omit<RequestInit, 'method' | 'body'>\n ): Promise<Schema.User> {\n return this.core.request({\n method: 'PUT',\n path: `/v1/users/${encodeURIComponent(userId)}`,\n body,\n ...(init ?? {}),\n });\n }\n\n /**\n * GET /v1/users/{userId}/effective-user-resources-roles*\n * @summary List effective user resources roles*\n * @description Retrieves all resources and roles for a user, including inherited roles from parent resources. The response indicates whether each role is directly assigned or inherited through resource hierarchies.*/\n listEffectiveUserResourcesRoles(\n userId: string,\n init?: Omit<RequestInit, 'method' | 'body'>\n ): Promise<Schema.UserResourceList> {\n return this.core.request({\n method: 'GET',\n path: `/v1/users/${encodeURIComponent(userId)}/effective-user-resources-roles`,\n ...(init ?? {}),\n });\n }\n}\n"],"mappings":";AAAA,OAA4B;AAGrB,IAAM,eAAN,MAAmB;AAAA,EACxB,YAAoB,MAAmB;AAAnB;AAAA,EAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxC,KACE,OACA,MAC0B;AAC1B,WAAO,KAAK,KAAK,QAAQ;AAAA,MACvB,QAAQ;AAAA,MACR,MAAM;AAAA,MACN;AAAA,MACA,GAAI,QAAQ,CAAC;AAAA,IACf,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OACE,MACA,MACsB;AACtB,WAAO,KAAK,KAAK,QAAQ;AAAA,MACvB,QAAQ;AAAA,MACR,MAAM;AAAA,MACN;AAAA,MACA,GAAI,QAAQ,CAAC;AAAA,IACf,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,QAAgB,MAA+D;AACpF,WAAO,KAAK,KAAK,QAAQ;AAAA,MACvB,QAAQ;AAAA,MACR,MAAM,aAAa,mBAAmB,MAAM,CAAC;AAAA,MAC7C,GAAI,QAAQ,CAAC;AAAA,IACf,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAK,QAAgB,MAAmE;AACtF,WAAO,KAAK,KAAK,QAAQ;AAAA,MACvB,QAAQ;AAAA,MACR,MAAM,aAAa,mBAAmB,MAAM,CAAC;AAAA,MAC7C,GAAI,QAAQ,CAAC;AAAA,IACf,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OACE,QACA,MACA,MACsB;AACtB,WAAO,KAAK,KAAK,QAAQ;AAAA,MACvB,QAAQ;AAAA,MACR,MAAM,aAAa,mBAAmB,MAAM,CAAC;AAAA,MAC7C;AAAA,MACA,GAAI,QAAQ,CAAC;AAAA,IACf,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gCACE,QACA,MACkC;AAClC,WAAO,KAAK,KAAK,QAAQ;AAAA,MACvB,QAAQ;AAAA,MACR,MAAM,aAAa,mBAAmB,MAAM,CAAC;AAAA,MAC7C,GAAI,QAAQ,CAAC;AAAA,IACf,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/dist/token-verifier.cjs
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/token-verifier.ts
|
|
31
|
-
var token_verifier_exports = {};
|
|
32
|
-
__export(token_verifier_exports, {
|
|
33
|
-
TokenVerifier: () => TokenVerifier,
|
|
34
|
-
verifyToken: () => verifyToken
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(token_verifier_exports);
|
|
37
|
-
|
|
38
|
-
// src/client.ts
|
|
39
|
-
var import_fetch = require("@blimu/fetch");
|
|
40
|
-
var import_fetch2 = require("@blimu/fetch");
|
|
41
|
-
|
|
42
|
-
// src/token-verifier.ts
|
|
43
|
-
var crypto = __toESM(require("crypto"));
|
|
44
|
-
var jwt = __toESM(require("jsonwebtoken"));
|
|
45
|
-
var TokenVerifier = class {
|
|
46
|
-
cache = /* @__PURE__ */ new Map();
|
|
47
|
-
cacheTTL;
|
|
48
|
-
runtimeApiUrl;
|
|
49
|
-
constructor(options) {
|
|
50
|
-
this.cacheTTL = options?.cacheTTL ?? 60 * 60 * 1e3;
|
|
51
|
-
this.runtimeApiUrl = options?.runtimeApiUrl ?? "https://api.blimu.dev";
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Fetch JWK Set from runtime-api
|
|
55
|
-
*/
|
|
56
|
-
async fetchJWKSet(endpoint, headers) {
|
|
57
|
-
console.log(`[TokenVerifier] \u{1F4E1} Fetching JWK Set from: ${endpoint}`);
|
|
58
|
-
if (headers) {
|
|
59
|
-
console.log(
|
|
60
|
-
`[TokenVerifier] \u{1F4E1} Request headers: ${JSON.stringify(Object.keys(headers).map((k) => `${k}: ${k === "x-api-key" ? "***" : headers[k]}`))}`
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
const response = await fetch(endpoint, {
|
|
64
|
-
method: "GET",
|
|
65
|
-
headers: {
|
|
66
|
-
"Content-Type": "application/json",
|
|
67
|
-
...headers
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
console.log(`[TokenVerifier] \u{1F4E1} Response status: ${response.status} ${response.statusText}`);
|
|
71
|
-
if (!response.ok) {
|
|
72
|
-
const errorText = await response.text();
|
|
73
|
-
console.error(`[TokenVerifier] \u274C Failed to fetch JWKs: ${response.status} ${errorText}`);
|
|
74
|
-
throw new import_fetch.FetchError("Failed to fetch JWKs", response.status, errorText);
|
|
75
|
-
}
|
|
76
|
-
const jwkSet = await response.json();
|
|
77
|
-
console.log(`[TokenVerifier] \u2705 Successfully fetched JWK Set with ${jwkSet.keys.length} keys`);
|
|
78
|
-
return jwkSet;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Convert JWK to KeyObject
|
|
82
|
-
*/
|
|
83
|
-
jwkToKeyObject(jwk) {
|
|
84
|
-
return crypto.createPublicKey({
|
|
85
|
-
key: {
|
|
86
|
-
kty: jwk.kty,
|
|
87
|
-
n: jwk.n,
|
|
88
|
-
e: jwk.e,
|
|
89
|
-
alg: jwk.alg
|
|
90
|
-
},
|
|
91
|
-
format: "jwk"
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Get public key for a specific key ID
|
|
96
|
-
*/
|
|
97
|
-
async getPublicKey(kid, cacheKey, endpoint, headers) {
|
|
98
|
-
const cached = this.cache.get(cacheKey);
|
|
99
|
-
if (cached && cached.expiresAt > Date.now()) {
|
|
100
|
-
console.log(`[TokenVerifier] \u2705 Using cached key for kid: ${kid}`);
|
|
101
|
-
return cached.key;
|
|
102
|
-
}
|
|
103
|
-
console.log(`[TokenVerifier] \u{1F50D} Cache miss or expired. Fetching new key for kid: ${kid}`);
|
|
104
|
-
const jwkSet = await this.fetchJWKSet(endpoint, headers);
|
|
105
|
-
const jwk = jwkSet.keys.find((k) => k.kid === kid);
|
|
106
|
-
if (!jwk) {
|
|
107
|
-
const availableKids = jwkSet.keys.map((k) => k.kid).join(", ");
|
|
108
|
-
console.error(
|
|
109
|
-
`[TokenVerifier] \u274C Key with kid '${kid}' not found in JWK Set. Available kids: ${availableKids}`
|
|
110
|
-
);
|
|
111
|
-
throw new Error(
|
|
112
|
-
`Key with kid '${kid}' not found in JWK Set. Available kids: ${availableKids}`
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
console.log(`[TokenVerifier] \u2705 Found key with kid: ${kid}`);
|
|
116
|
-
const keyObject = this.jwkToKeyObject(jwk);
|
|
117
|
-
this.cache.set(cacheKey, {
|
|
118
|
-
key: keyObject,
|
|
119
|
-
kid,
|
|
120
|
-
expiresAt: Date.now() + this.cacheTTL
|
|
121
|
-
});
|
|
122
|
-
return keyObject;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Verify JWT token using JWKs from runtime-api
|
|
126
|
-
*/
|
|
127
|
-
async verifyToken(options) {
|
|
128
|
-
const { url, secretKey, token, runtimeApiUrl } = options;
|
|
129
|
-
if (!url && !secretKey) {
|
|
130
|
-
throw new Error("Either url or secretKey must be provided");
|
|
131
|
-
}
|
|
132
|
-
if (url && secretKey) {
|
|
133
|
-
throw new Error("Cannot provide both url and secretKey");
|
|
134
|
-
}
|
|
135
|
-
const decoded = jwt.decode(token, { complete: true });
|
|
136
|
-
if (!decoded || typeof decoded === "string") {
|
|
137
|
-
throw new Error("Invalid token format");
|
|
138
|
-
}
|
|
139
|
-
const header = decoded.header;
|
|
140
|
-
if (!header.kid) {
|
|
141
|
-
throw new Error("Token missing kid in header");
|
|
142
|
-
}
|
|
143
|
-
let endpoint;
|
|
144
|
-
let cacheKey;
|
|
145
|
-
let headers;
|
|
146
|
-
if (secretKey) {
|
|
147
|
-
const apiUrl = runtimeApiUrl ?? this.runtimeApiUrl;
|
|
148
|
-
endpoint = `${apiUrl}/v1/auth/.well-known/jwks.json`;
|
|
149
|
-
cacheKey = secretKey;
|
|
150
|
-
headers = {
|
|
151
|
-
"x-api-key": secretKey
|
|
152
|
-
};
|
|
153
|
-
console.log(
|
|
154
|
-
`[TokenVerifier] \u{1F50D} Verifying token with kid: ${header.kid}, endpoint: ${endpoint}`
|
|
155
|
-
);
|
|
156
|
-
} else {
|
|
157
|
-
endpoint = url;
|
|
158
|
-
cacheKey = url;
|
|
159
|
-
console.log(
|
|
160
|
-
`[TokenVerifier] \u{1F50D} Verifying token with kid: ${header.kid}, endpoint: ${endpoint}`
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
let publicKey;
|
|
164
|
-
try {
|
|
165
|
-
publicKey = await this.getPublicKey(header.kid, cacheKey, endpoint, headers);
|
|
166
|
-
console.log(`[TokenVerifier] \u2705 Successfully retrieved public key for kid: ${header.kid}`);
|
|
167
|
-
} catch (error) {
|
|
168
|
-
console.error(
|
|
169
|
-
`[TokenVerifier] \u274C Failed to get public key (first attempt): ${error instanceof Error ? error.message : String(error)}`
|
|
170
|
-
);
|
|
171
|
-
this.clearCache(cacheKey);
|
|
172
|
-
console.log(`[TokenVerifier] \u{1F504} Retrying after cache clear...`);
|
|
173
|
-
try {
|
|
174
|
-
publicKey = await this.getPublicKey(header.kid, cacheKey, endpoint, headers);
|
|
175
|
-
console.log(
|
|
176
|
-
`[TokenVerifier] \u2705 Successfully retrieved public key for kid: ${header.kid} (retry)`
|
|
177
|
-
);
|
|
178
|
-
} catch (retryError) {
|
|
179
|
-
console.error(
|
|
180
|
-
`[TokenVerifier] \u274C Failed to get public key (retry): ${retryError instanceof Error ? retryError.message : String(retryError)}`
|
|
181
|
-
);
|
|
182
|
-
throw retryError;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
try {
|
|
186
|
-
const payload = jwt.verify(token, publicKey, {
|
|
187
|
-
algorithms: ["RS256"]
|
|
188
|
-
});
|
|
189
|
-
console.log(`[TokenVerifier] \u2705 Token verified successfully`);
|
|
190
|
-
return payload;
|
|
191
|
-
} catch (error) {
|
|
192
|
-
console.error(
|
|
193
|
-
`[TokenVerifier] \u274C JWT verification failed: ${error instanceof Error ? error.message : String(error)}`
|
|
194
|
-
);
|
|
195
|
-
throw error;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Clear cache (useful for testing or key rotation)
|
|
200
|
-
*/
|
|
201
|
-
clearCache(secretKeyOrUrl) {
|
|
202
|
-
if (secretKeyOrUrl) {
|
|
203
|
-
this.cache.delete(secretKeyOrUrl);
|
|
204
|
-
} else {
|
|
205
|
-
this.cache.clear();
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
async function verifyToken(options) {
|
|
210
|
-
const verifier = new TokenVerifier();
|
|
211
|
-
return verifier.verifyToken(options);
|
|
212
|
-
}
|
|
213
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
214
|
-
0 && (module.exports = {
|
|
215
|
-
TokenVerifier,
|
|
216
|
-
verifyToken
|
|
217
|
-
});
|
|
218
|
-
//# sourceMappingURL=token-verifier.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/token-verifier.ts","../src/client.ts"],"sourcesContent":["import { FetchError } from './client';\nimport * as crypto from 'crypto';\nimport * as jwt from 'jsonwebtoken';\n\nexport interface JWK {\n kty: string;\n use: string;\n kid: string;\n alg: string;\n n: string;\n e: string;\n}\n\nexport interface JWKSet {\n keys: JWK[];\n}\n\ninterface CachedJWK {\n key: crypto.KeyObject;\n kid: string;\n expiresAt: number;\n}\n\nexport interface VerifyTokenOptions {\n url?: string; // Direct URL to JWK endpoint (for custom scenarios)\n secretKey?: string; // API key/secret key - uses runtimeApiUrl + JWK endpoint\n token: string;\n runtimeApiUrl?: string | undefined; // Optional override for runtime API URL\n}\n\nexport interface TokenVerifierOptions {\n runtimeApiUrl?: string | undefined;\n cacheTTL?: number | undefined; // Default: 1 hour\n}\n\nexport class TokenVerifier {\n private readonly cache = new Map<string, CachedJWK>();\n private readonly cacheTTL: number;\n private readonly runtimeApiUrl: string;\n\n constructor(options?: TokenVerifierOptions) {\n this.cacheTTL = options?.cacheTTL ?? 60 * 60 * 1000; // 1 hour\n\n this.runtimeApiUrl = options?.runtimeApiUrl ?? 'https://api.blimu.dev';\n }\n\n /**\n * Fetch JWK Set from runtime-api\n */\n private async fetchJWKSet(endpoint: string, headers?: Record<string, string>): Promise<JWKSet> {\n console.log(`[TokenVerifier] 📡 Fetching JWK Set from: ${endpoint}`);\n if (headers) {\n console.log(\n `[TokenVerifier] 📡 Request headers: ${JSON.stringify(Object.keys(headers).map((k) => `${k}: ${k === 'x-api-key' ? '***' : headers[k]}`))}`\n );\n }\n\n const response = await fetch(endpoint, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n console.log(`[TokenVerifier] 📡 Response status: ${response.status} ${response.statusText}`);\n\n if (!response.ok) {\n const errorText = await response.text();\n console.error(`[TokenVerifier] ❌ Failed to fetch JWKs: ${response.status} ${errorText}`);\n throw new FetchError('Failed to fetch JWKs', response.status, errorText);\n }\n\n const jwkSet = (await response.json()) as JWKSet;\n console.log(`[TokenVerifier] ✅ Successfully fetched JWK Set with ${jwkSet.keys.length} keys`);\n return jwkSet;\n }\n\n /**\n * Convert JWK to KeyObject\n */\n private jwkToKeyObject(jwk: JWK): crypto.KeyObject {\n return crypto.createPublicKey({\n key: {\n kty: jwk.kty,\n n: jwk.n,\n e: jwk.e,\n alg: jwk.alg,\n },\n format: 'jwk',\n });\n }\n\n /**\n * Get public key for a specific key ID\n */\n private async getPublicKey(\n kid: string,\n cacheKey: string,\n endpoint: string,\n headers?: Record<string, string>\n ): Promise<crypto.KeyObject> {\n // Check cache first\n const cached = this.cache.get(cacheKey);\n if (cached && cached.expiresAt > Date.now()) {\n console.log(`[TokenVerifier] ✅ Using cached key for kid: ${kid}`);\n return cached.key;\n }\n\n console.log(`[TokenVerifier] 🔍 Cache miss or expired. Fetching new key for kid: ${kid}`);\n\n // Fetch JWK Set\n const jwkSet = await this.fetchJWKSet(endpoint, headers);\n\n // Find the key with matching kid\n const jwk = jwkSet.keys.find((k) => k.kid === kid);\n if (!jwk) {\n const availableKids = jwkSet.keys.map((k) => k.kid).join(', ');\n console.error(\n `[TokenVerifier] ❌ Key with kid '${kid}' not found in JWK Set. Available kids: ${availableKids}`\n );\n throw new Error(\n `Key with kid '${kid}' not found in JWK Set. Available kids: ${availableKids}`\n );\n }\n\n console.log(`[TokenVerifier] ✅ Found key with kid: ${kid}`);\n\n // Convert JWK to KeyObject\n const keyObject = this.jwkToKeyObject(jwk);\n\n // Cache the key\n this.cache.set(cacheKey, {\n key: keyObject,\n kid,\n expiresAt: Date.now() + this.cacheTTL,\n });\n\n return keyObject;\n }\n\n /**\n * Verify JWT token using JWKs from runtime-api\n */\n async verifyToken<T = unknown>(options: VerifyTokenOptions): Promise<T> {\n const { url, secretKey, token, runtimeApiUrl } = options;\n\n if (!url && !secretKey) {\n throw new Error('Either url or secretKey must be provided');\n }\n\n if (url && secretKey) {\n throw new Error('Cannot provide both url and secretKey');\n }\n\n // Decode token header to get kid (without verification)\n const decoded = jwt.decode(token, { complete: true });\n if (!decoded || typeof decoded === 'string') {\n throw new Error('Invalid token format');\n }\n\n const header = decoded.header;\n if (!header.kid) {\n throw new Error('Token missing kid in header');\n }\n\n let endpoint: string;\n let cacheKey: string;\n let headers: Record<string, string> | undefined;\n\n if (secretKey) {\n // Use secretKey with runtimeApiUrl\n const apiUrl = runtimeApiUrl ?? this.runtimeApiUrl;\n endpoint = `${apiUrl}/v1/auth/.well-known/jwks.json`;\n cacheKey = secretKey;\n headers = {\n 'x-api-key': secretKey,\n };\n console.log(\n `[TokenVerifier] 🔍 Verifying token with kid: ${header.kid}, endpoint: ${endpoint}`\n );\n } else {\n // Use direct URL\n endpoint = url!;\n cacheKey = url!;\n console.log(\n `[TokenVerifier] 🔍 Verifying token with kid: ${header.kid}, endpoint: ${endpoint}`\n );\n }\n\n // Get public key for this kid\n let publicKey: crypto.KeyObject;\n try {\n publicKey = await this.getPublicKey(header.kid, cacheKey, endpoint, headers);\n console.log(`[TokenVerifier] ✅ Successfully retrieved public key for kid: ${header.kid}`);\n } catch (error) {\n console.error(\n `[TokenVerifier] ❌ Failed to get public key (first attempt): ${error instanceof Error ? error.message : String(error)}`\n );\n // If verification fails, clear cache and retry once (handles key rotation)\n this.clearCache(cacheKey);\n console.log(`[TokenVerifier] 🔄 Retrying after cache clear...`);\n try {\n publicKey = await this.getPublicKey(header.kid, cacheKey, endpoint, headers);\n console.log(\n `[TokenVerifier] ✅ Successfully retrieved public key for kid: ${header.kid} (retry)`\n );\n } catch (retryError) {\n console.error(\n `[TokenVerifier] ❌ Failed to get public key (retry): ${retryError instanceof Error ? retryError.message : String(retryError)}`\n );\n throw retryError;\n }\n }\n\n // Verify token\n try {\n const payload = jwt.verify(token, publicKey, {\n algorithms: ['RS256'],\n }) as T;\n console.log(`[TokenVerifier] ✅ Token verified successfully`);\n return payload;\n } catch (error) {\n console.error(\n `[TokenVerifier] ❌ JWT verification failed: ${error instanceof Error ? error.message : String(error)}`\n );\n throw error;\n }\n }\n\n /**\n * Clear cache (useful for testing or key rotation)\n */\n clearCache(secretKeyOrUrl?: string): void {\n if (secretKeyOrUrl) {\n this.cache.delete(secretKeyOrUrl);\n } else {\n this.cache.clear();\n }\n }\n}\n\n/**\n * Convenience function to verify a token\n */\nexport async function verifyToken<T = unknown>(options: VerifyTokenOptions): Promise<T> {\n const verifier = new TokenVerifier();\n return verifier.verifyToken<T>(options);\n}\n","import { FetchClient, FetchError } from '@blimu/fetch';\nimport { type FetchClientConfig, type ApiKeyAuthStrategy } from '@blimu/fetch';\nimport { buildAuthStrategies } from './auth-strategies';\nimport { BulkResourcesService } from './services/bulk_resources';\nimport { BulkRolesService } from './services/bulk_roles';\nimport { EntitlementsService } from './services/entitlements';\nimport { PlansService } from './services/plans';\nimport { ResourceMembersService } from './services/resource_members';\nimport { ResourcesService } from './services/resources';\nimport { RolesService } from './services/roles';\nimport { UsageService } from './services/usage';\nimport { UsersService } from './services/users';\n\nexport type ClientOption = FetchClientConfig & {\n apiKey?: ApiKeyAuthStrategy['key'];\n};\n\nexport class Blimu {\n readonly bulkResources: BulkResourcesService;\n readonly bulkRoles: BulkRolesService;\n readonly entitlements: EntitlementsService;\n readonly plans: PlansService;\n readonly resourceMembers: ResourceMembersService;\n readonly resources: ResourcesService;\n readonly roles: RolesService;\n readonly usage: UsageService;\n readonly users: UsersService;\n\n constructor(options?: ClientOption) {\n const restCfg = { ...(options ?? {}) };\n delete restCfg.apiKey;\n\n const authStrategies = buildAuthStrategies(options ?? {});\n\n const core = new FetchClient({\n ...restCfg,\n baseURL: options?.baseURL ?? 'https://api.blimu.dev',\n ...(authStrategies.length > 0 ? { authStrategies } : {}),\n });\n\n this.bulkResources = new BulkResourcesService(core);\n this.bulkRoles = new BulkRolesService(core);\n this.entitlements = new EntitlementsService(core);\n this.plans = new PlansService(core);\n this.resourceMembers = new ResourceMembersService(core);\n this.resources = new ResourcesService(core);\n this.roles = new RolesService(core);\n this.usage = new UsageService(core);\n this.users = new UsersService(core);\n }\n}\n\n// Re-export FetchError for backward compatibility\nexport { FetchError };\nexport const BlimuError = FetchError;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAwC;AACxC,IAAAA,gBAAgE;;;ADAhE,aAAwB;AACxB,UAAqB;AAiCd,IAAM,gBAAN,MAAoB;AAAA,EACR,QAAQ,oBAAI,IAAuB;AAAA,EACnC;AAAA,EACA;AAAA,EAEjB,YAAY,SAAgC;AAC1C,SAAK,WAAW,SAAS,YAAY,KAAK,KAAK;AAE/C,SAAK,gBAAgB,SAAS,iBAAiB;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAc,YAAY,UAAkB,SAAmD;AAC7F,YAAQ,IAAI,oDAA6C,QAAQ,EAAE;AACnE,QAAI,SAAS;AACX,cAAQ;AAAA,QACN,8CAAuC,KAAK,UAAU,OAAO,KAAK,OAAO,EAAE,IAAI,C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,0 @@
|
|
|
1
|
-
interface JWK {
|
|
2
|
-
kty: string;
|
|
3
|
-
use: string;
|
|
4
|
-
kid: string;
|
|
5
|
-
alg: string;
|
|
6
|
-
n: string;
|
|
7
|
-
e: string;
|
|
8
|
-
}
|
|
9
|
-
interface JWKSet {
|
|
10
|
-
keys: JWK[];
|
|
11
|
-
}
|
|
12
|
-
interface VerifyTokenOptions {
|
|
13
|
-
url?: string;
|
|
14
|
-
secretKey?: string;
|
|
15
|
-
token: string;
|
|
16
|
-
runtimeApiUrl?: string | undefined;
|
|
17
|
-
}
|
|
18
|
-
interface TokenVerifierOptions {
|
|
19
|
-
runtimeApiUrl?: string | undefined;
|
|
20
|
-
cacheTTL?: number | undefined;
|
|
21
|
-
}
|
|
22
|
-
declare class TokenVerifier {
|
|
23
|
-
private readonly cache;
|
|
24
|
-
private readonly cacheTTL;
|
|
25
|
-
private readonly runtimeApiUrl;
|
|
26
|
-
constructor(options?: TokenVerifierOptions);
|
|
27
|
-
private fetchJWKSet;
|
|
28
|
-
private jwkToKeyObject;
|
|
29
|
-
private getPublicKey;
|
|
30
|
-
verifyToken<T = unknown>(options: VerifyTokenOptions): Promise<T>;
|
|
31
|
-
clearCache(secretKeyOrUrl?: string): void;
|
|
32
|
-
}
|
|
33
|
-
declare function verifyToken<T = unknown>(options: VerifyTokenOptions): Promise<T>;
|
|
34
|
-
|
|
35
|
-
export { type JWK, type JWKSet, TokenVerifier, type TokenVerifierOptions, type VerifyTokenOptions, verifyToken };
|
package/dist/token-verifier.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
interface JWK {
|
|
2
|
-
kty: string;
|
|
3
|
-
use: string;
|
|
4
|
-
kid: string;
|
|
5
|
-
alg: string;
|
|
6
|
-
n: string;
|
|
7
|
-
e: string;
|
|
8
|
-
}
|
|
9
|
-
interface JWKSet {
|
|
10
|
-
keys: JWK[];
|
|
11
|
-
}
|
|
12
|
-
interface VerifyTokenOptions {
|
|
13
|
-
url?: string;
|
|
14
|
-
secretKey?: string;
|
|
15
|
-
token: string;
|
|
16
|
-
runtimeApiUrl?: string | undefined;
|
|
17
|
-
}
|
|
18
|
-
interface TokenVerifierOptions {
|
|
19
|
-
runtimeApiUrl?: string | undefined;
|
|
20
|
-
cacheTTL?: number | undefined;
|
|
21
|
-
}
|
|
22
|
-
declare class TokenVerifier {
|
|
23
|
-
private readonly cache;
|
|
24
|
-
private readonly cacheTTL;
|
|
25
|
-
private readonly runtimeApiUrl;
|
|
26
|
-
constructor(options?: TokenVerifierOptions);
|
|
27
|
-
private fetchJWKSet;
|
|
28
|
-
private jwkToKeyObject;
|
|
29
|
-
private getPublicKey;
|
|
30
|
-
verifyToken<T = unknown>(options: VerifyTokenOptions): Promise<T>;
|
|
31
|
-
clearCache(secretKeyOrUrl?: string): void;
|
|
32
|
-
}
|
|
33
|
-
declare function verifyToken<T = unknown>(options: VerifyTokenOptions): Promise<T>;
|
|
34
|
-
|
|
35
|
-
export { type JWK, type JWKSet, TokenVerifier, type TokenVerifierOptions, type VerifyTokenOptions, verifyToken };
|
package/dist/token-verifier.mjs
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
// src/client.ts
|
|
2
|
-
import { FetchClient, FetchError } from "@blimu/fetch";
|
|
3
|
-
import "@blimu/fetch";
|
|
4
|
-
|
|
5
|
-
// src/token-verifier.ts
|
|
6
|
-
import * as crypto from "crypto";
|
|
7
|
-
import * as jwt from "jsonwebtoken";
|
|
8
|
-
var TokenVerifier = class {
|
|
9
|
-
cache = /* @__PURE__ */ new Map();
|
|
10
|
-
cacheTTL;
|
|
11
|
-
runtimeApiUrl;
|
|
12
|
-
constructor(options) {
|
|
13
|
-
this.cacheTTL = options?.cacheTTL ?? 60 * 60 * 1e3;
|
|
14
|
-
this.runtimeApiUrl = options?.runtimeApiUrl ?? "https://api.blimu.dev";
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Fetch JWK Set from runtime-api
|
|
18
|
-
*/
|
|
19
|
-
async fetchJWKSet(endpoint, headers) {
|
|
20
|
-
console.log(`[TokenVerifier] \u{1F4E1} Fetching JWK Set from: ${endpoint}`);
|
|
21
|
-
if (headers) {
|
|
22
|
-
console.log(
|
|
23
|
-
`[TokenVerifier] \u{1F4E1} Request headers: ${JSON.stringify(Object.keys(headers).map((k) => `${k}: ${k === "x-api-key" ? "***" : headers[k]}`))}`
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
const response = await fetch(endpoint, {
|
|
27
|
-
method: "GET",
|
|
28
|
-
headers: {
|
|
29
|
-
"Content-Type": "application/json",
|
|
30
|
-
...headers
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
console.log(`[TokenVerifier] \u{1F4E1} Response status: ${response.status} ${response.statusText}`);
|
|
34
|
-
if (!response.ok) {
|
|
35
|
-
const errorText = await response.text();
|
|
36
|
-
console.error(`[TokenVerifier] \u274C Failed to fetch JWKs: ${response.status} ${errorText}`);
|
|
37
|
-
throw new FetchError("Failed to fetch JWKs", response.status, errorText);
|
|
38
|
-
}
|
|
39
|
-
const jwkSet = await response.json();
|
|
40
|
-
console.log(`[TokenVerifier] \u2705 Successfully fetched JWK Set with ${jwkSet.keys.length} keys`);
|
|
41
|
-
return jwkSet;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Convert JWK to KeyObject
|
|
45
|
-
*/
|
|
46
|
-
jwkToKeyObject(jwk) {
|
|
47
|
-
return crypto.createPublicKey({
|
|
48
|
-
key: {
|
|
49
|
-
kty: jwk.kty,
|
|
50
|
-
n: jwk.n,
|
|
51
|
-
e: jwk.e,
|
|
52
|
-
alg: jwk.alg
|
|
53
|
-
},
|
|
54
|
-
format: "jwk"
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Get public key for a specific key ID
|
|
59
|
-
*/
|
|
60
|
-
async getPublicKey(kid, cacheKey, endpoint, headers) {
|
|
61
|
-
const cached = this.cache.get(cacheKey);
|
|
62
|
-
if (cached && cached.expiresAt > Date.now()) {
|
|
63
|
-
console.log(`[TokenVerifier] \u2705 Using cached key for kid: ${kid}`);
|
|
64
|
-
return cached.key;
|
|
65
|
-
}
|
|
66
|
-
console.log(`[TokenVerifier] \u{1F50D} Cache miss or expired. Fetching new key for kid: ${kid}`);
|
|
67
|
-
const jwkSet = await this.fetchJWKSet(endpoint, headers);
|
|
68
|
-
const jwk = jwkSet.keys.find((k) => k.kid === kid);
|
|
69
|
-
if (!jwk) {
|
|
70
|
-
const availableKids = jwkSet.keys.map((k) => k.kid).join(", ");
|
|
71
|
-
console.error(
|
|
72
|
-
`[TokenVerifier] \u274C Key with kid '${kid}' not found in JWK Set. Available kids: ${availableKids}`
|
|
73
|
-
);
|
|
74
|
-
throw new Error(
|
|
75
|
-
`Key with kid '${kid}' not found in JWK Set. Available kids: ${availableKids}`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
console.log(`[TokenVerifier] \u2705 Found key with kid: ${kid}`);
|
|
79
|
-
const keyObject = this.jwkToKeyObject(jwk);
|
|
80
|
-
this.cache.set(cacheKey, {
|
|
81
|
-
key: keyObject,
|
|
82
|
-
kid,
|
|
83
|
-
expiresAt: Date.now() + this.cacheTTL
|
|
84
|
-
});
|
|
85
|
-
return keyObject;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Verify JWT token using JWKs from runtime-api
|
|
89
|
-
*/
|
|
90
|
-
async verifyToken(options) {
|
|
91
|
-
const { url, secretKey, token, runtimeApiUrl } = options;
|
|
92
|
-
if (!url && !secretKey) {
|
|
93
|
-
throw new Error("Either url or secretKey must be provided");
|
|
94
|
-
}
|
|
95
|
-
if (url && secretKey) {
|
|
96
|
-
throw new Error("Cannot provide both url and secretKey");
|
|
97
|
-
}
|
|
98
|
-
const decoded = jwt.decode(token, { complete: true });
|
|
99
|
-
if (!decoded || typeof decoded === "string") {
|
|
100
|
-
throw new Error("Invalid token format");
|
|
101
|
-
}
|
|
102
|
-
const header = decoded.header;
|
|
103
|
-
if (!header.kid) {
|
|
104
|
-
throw new Error("Token missing kid in header");
|
|
105
|
-
}
|
|
106
|
-
let endpoint;
|
|
107
|
-
let cacheKey;
|
|
108
|
-
let headers;
|
|
109
|
-
if (secretKey) {
|
|
110
|
-
const apiUrl = runtimeApiUrl ?? this.runtimeApiUrl;
|
|
111
|
-
endpoint = `${apiUrl}/v1/auth/.well-known/jwks.json`;
|
|
112
|
-
cacheKey = secretKey;
|
|
113
|
-
headers = {
|
|
114
|
-
"x-api-key": secretKey
|
|
115
|
-
};
|
|
116
|
-
console.log(
|
|
117
|
-
`[TokenVerifier] \u{1F50D} Verifying token with kid: ${header.kid}, endpoint: ${endpoint}`
|
|
118
|
-
);
|
|
119
|
-
} else {
|
|
120
|
-
endpoint = url;
|
|
121
|
-
cacheKey = url;
|
|
122
|
-
console.log(
|
|
123
|
-
`[TokenVerifier] \u{1F50D} Verifying token with kid: ${header.kid}, endpoint: ${endpoint}`
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
let publicKey;
|
|
127
|
-
try {
|
|
128
|
-
publicKey = await this.getPublicKey(header.kid, cacheKey, endpoint, headers);
|
|
129
|
-
console.log(`[TokenVerifier] \u2705 Successfully retrieved public key for kid: ${header.kid}`);
|
|
130
|
-
} catch (error) {
|
|
131
|
-
console.error(
|
|
132
|
-
`[TokenVerifier] \u274C Failed to get public key (first attempt): ${error instanceof Error ? error.message : String(error)}`
|
|
133
|
-
);
|
|
134
|
-
this.clearCache(cacheKey);
|
|
135
|
-
console.log(`[TokenVerifier] \u{1F504} Retrying after cache clear...`);
|
|
136
|
-
try {
|
|
137
|
-
publicKey = await this.getPublicKey(header.kid, cacheKey, endpoint, headers);
|
|
138
|
-
console.log(
|
|
139
|
-
`[TokenVerifier] \u2705 Successfully retrieved public key for kid: ${header.kid} (retry)`
|
|
140
|
-
);
|
|
141
|
-
} catch (retryError) {
|
|
142
|
-
console.error(
|
|
143
|
-
`[TokenVerifier] \u274C Failed to get public key (retry): ${retryError instanceof Error ? retryError.message : String(retryError)}`
|
|
144
|
-
);
|
|
145
|
-
throw retryError;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
try {
|
|
149
|
-
const payload = jwt.verify(token, publicKey, {
|
|
150
|
-
algorithms: ["RS256"]
|
|
151
|
-
});
|
|
152
|
-
console.log(`[TokenVerifier] \u2705 Token verified successfully`);
|
|
153
|
-
return payload;
|
|
154
|
-
} catch (error) {
|
|
155
|
-
console.error(
|
|
156
|
-
`[TokenVerifier] \u274C JWT verification failed: ${error instanceof Error ? error.message : String(error)}`
|
|
157
|
-
);
|
|
158
|
-
throw error;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Clear cache (useful for testing or key rotation)
|
|
163
|
-
*/
|
|
164
|
-
clearCache(secretKeyOrUrl) {
|
|
165
|
-
if (secretKeyOrUrl) {
|
|
166
|
-
this.cache.delete(secretKeyOrUrl);
|
|
167
|
-
} else {
|
|
168
|
-
this.cache.clear();
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
async function verifyToken(options) {
|
|
173
|
-
const verifier = new TokenVerifier();
|
|
174
|
-
return verifier.verifyToken(options);
|
|
175
|
-
}
|
|
176
|
-
export {
|
|
177
|
-
TokenVerifier,
|
|
178
|
-
verifyToken
|
|
179
|
-
};
|
|
180
|
-
//# sourceMappingURL=token-verifier.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/token-verifier.ts"],"sourcesContent":["import { FetchClient, FetchError } from '@blimu/fetch';\nimport { type FetchClientConfig, type ApiKeyAuthStrategy } from '@blimu/fetch';\nimport { buildAuthStrategies } from './auth-strategies';\nimport { BulkResourcesService } from './services/bulk_resources';\nimport { BulkRolesService } from './services/bulk_roles';\nimport { EntitlementsService } from './services/entitlements';\nimport { PlansService } from './services/plans';\nimport { ResourceMembersService } from './services/resource_members';\nimport { ResourcesService } from './services/resources';\nimport { RolesService } from './services/roles';\nimport { UsageService } from './services/usage';\nimport { UsersService } from './services/users';\n\nexport type ClientOption = FetchClientConfig & {\n apiKey?: ApiKeyAuthStrategy['key'];\n};\n\nexport class Blimu {\n readonly bulkResources: BulkResourcesService;\n readonly bulkRoles: BulkRolesService;\n readonly entitlements: EntitlementsService;\n readonly plans: PlansService;\n readonly resourceMembers: ResourceMembersService;\n readonly resources: ResourcesService;\n readonly roles: RolesService;\n readonly usage: UsageService;\n readonly users: UsersService;\n\n constructor(options?: ClientOption) {\n const restCfg = { ...(options ?? {}) };\n delete restCfg.apiKey;\n\n const authStrategies = buildAuthStrategies(options ?? {});\n\n const core = new FetchClient({\n ...restCfg,\n baseURL: options?.baseURL ?? 'https://api.blimu.dev',\n ...(authStrategies.length > 0 ? { authStrategies } : {}),\n });\n\n this.bulkResources = new BulkResourcesService(core);\n this.bulkRoles = new BulkRolesService(core);\n this.entitlements = new EntitlementsService(core);\n this.plans = new PlansService(core);\n this.resourceMembers = new ResourceMembersService(core);\n this.resources = new ResourcesService(core);\n this.roles = new RolesService(core);\n this.usage = new UsageService(core);\n this.users = new UsersService(core);\n }\n}\n\n// Re-export FetchError for backward compatibility\nexport { FetchError };\nexport const BlimuError = FetchError;\n","import { FetchError } from './client';\nimport * as crypto from 'crypto';\nimport * as jwt from 'jsonwebtoken';\n\nexport interface JWK {\n kty: string;\n use: string;\n kid: string;\n alg: string;\n n: string;\n e: string;\n}\n\nexport interface JWKSet {\n keys: JWK[];\n}\n\ninterface CachedJWK {\n key: crypto.KeyObject;\n kid: string;\n expiresAt: number;\n}\n\nexport interface VerifyTokenOptions {\n url?: string; // Direct URL to JWK endpoint (for custom scenarios)\n secretKey?: string; // API key/secret key - uses runtimeApiUrl + JWK endpoint\n token: string;\n runtimeApiUrl?: string | undefined; // Optional override for runtime API URL\n}\n\nexport interface TokenVerifierOptions {\n runtimeApiUrl?: string | undefined;\n cacheTTL?: number | undefined; // Default: 1 hour\n}\n\nexport class TokenVerifier {\n private readonly cache = new Map<string, CachedJWK>();\n private readonly cacheTTL: number;\n private readonly runtimeApiUrl: string;\n\n constructor(options?: TokenVerifierOptions) {\n this.cacheTTL = options?.cacheTTL ?? 60 * 60 * 1000; // 1 hour\n\n this.runtimeApiUrl = options?.runtimeApiUrl ?? 'https://api.blimu.dev';\n }\n\n /**\n * Fetch JWK Set from runtime-api\n */\n private async fetchJWKSet(endpoint: string, headers?: Record<string, string>): Promise<JWKSet> {\n console.log(`[TokenVerifier] 📡 Fetching JWK Set from: ${endpoint}`);\n if (headers) {\n console.log(\n `[TokenVerifier] 📡 Request headers: ${JSON.stringify(Object.keys(headers).map((k) => `${k}: ${k === 'x-api-key' ? '***' : headers[k]}`))}`\n );\n }\n\n const response = await fetch(endpoint, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n console.log(`[TokenVerifier] 📡 Response status: ${response.status} ${response.statusText}`);\n\n if (!response.ok) {\n const errorText = await response.text();\n console.error(`[TokenVerifier] ❌ Failed to fetch JWKs: ${response.status} ${errorText}`);\n throw new FetchError('Failed to fetch JWKs', response.status, errorText);\n }\n\n const jwkSet = (await response.json()) as JWKSet;\n console.log(`[TokenVerifier] ✅ Successfully fetched JWK Set with ${jwkSet.keys.length} keys`);\n return jwkSet;\n }\n\n /**\n * Convert JWK to KeyObject\n */\n private jwkToKeyObject(jwk: JWK): crypto.KeyObject {\n return crypto.createPublicKey({\n key: {\n kty: jwk.kty,\n n: jwk.n,\n e: jwk.e,\n alg: jwk.alg,\n },\n format: 'jwk',\n });\n }\n\n /**\n * Get public key for a specific key ID\n */\n private async getPublicKey(\n kid: string,\n cacheKey: string,\n endpoint: string,\n headers?: Record<string, string>\n ): Promise<crypto.KeyObject> {\n // Check cache first\n const cached = this.cache.get(cacheKey);\n if (cached && cached.expiresAt > Date.now()) {\n console.log(`[TokenVerifier] ✅ Using cached key for kid: ${kid}`);\n return cached.key;\n }\n\n console.log(`[TokenVerifier] 🔍 Cache miss or expired. Fetching new key for kid: ${kid}`);\n\n // Fetch JWK Set\n const jwkSet = await this.fetchJWKSet(endpoint, headers);\n\n // Find the key with matching kid\n const jwk = jwkSet.keys.find((k) => k.kid === kid);\n if (!jwk) {\n const availableKids = jwkSet.keys.map((k) => k.kid).join(', ');\n console.error(\n `[TokenVerifier] ❌ Key with kid '${kid}' not found in JWK Set. Available kids: ${availableKids}`\n );\n throw new Error(\n `Key with kid '${kid}' not found in JWK Set. Available kids: ${availableKids}`\n );\n }\n\n console.log(`[TokenVerifier] ✅ Found key with kid: ${kid}`);\n\n // Convert JWK to KeyObject\n const keyObject = this.jwkToKeyObject(jwk);\n\n // Cache the key\n this.cache.set(cacheKey, {\n key: keyObject,\n kid,\n expiresAt: Date.now() + this.cacheTTL,\n });\n\n return keyObject;\n }\n\n /**\n * Verify JWT token using JWKs from runtime-api\n */\n async verifyToken<T = unknown>(options: VerifyTokenOptions): Promise<T> {\n const { url, secretKey, token, runtimeApiUrl } = options;\n\n if (!url && !secretKey) {\n throw new Error('Either url or secretKey must be provided');\n }\n\n if (url && secretKey) {\n throw new Error('Cannot provide both url and secretKey');\n }\n\n // Decode token header to get kid (without verification)\n const decoded = jwt.decode(token, { complete: true });\n if (!decoded || typeof decoded === 'string') {\n throw new Error('Invalid token format');\n }\n\n const header = decoded.header;\n if (!header.kid) {\n throw new Error('Token missing kid in header');\n }\n\n let endpoint: string;\n let cacheKey: string;\n let headers: Record<string, string> | undefined;\n\n if (secretKey) {\n // Use secretKey with runtimeApiUrl\n const apiUrl = runtimeApiUrl ?? this.runtimeApiUrl;\n endpoint = `${apiUrl}/v1/auth/.well-known/jwks.json`;\n cacheKey = secretKey;\n headers = {\n 'x-api-key': secretKey,\n };\n console.log(\n `[TokenVerifier] 🔍 Verifying token with kid: ${header.kid}, endpoint: ${endpoint}`\n );\n } else {\n // Use direct URL\n endpoint = url!;\n cacheKey = url!;\n console.log(\n `[TokenVerifier] 🔍 Verifying token with kid: ${header.kid}, endpoint: ${endpoint}`\n );\n }\n\n // Get public key for this kid\n let publicKey: crypto.KeyObject;\n try {\n publicKey = await this.getPublicKey(header.kid, cacheKey, endpoint, headers);\n console.log(`[TokenVerifier] ✅ Successfully retrieved public key for kid: ${header.kid}`);\n } catch (error) {\n console.error(\n `[TokenVerifier] ❌ Failed to get public key (first attempt): ${error instanceof Error ? error.message : String(error)}`\n );\n // If verification fails, clear cache and retry once (handles key rotation)\n this.clearCache(cacheKey);\n console.log(`[TokenVerifier] 🔄 Retrying after cache clear...`);\n try {\n publicKey = await this.getPublicKey(header.kid, cacheKey, endpoint, headers);\n console.log(\n `[TokenVerifier] ✅ Successfully retrieved public key for kid: ${header.kid} (retry)`\n );\n } catch (retryError) {\n console.error(\n `[TokenVerifier] ❌ Failed to get public key (retry): ${retryError instanceof Error ? retryError.message : String(retryError)}`\n );\n throw retryError;\n }\n }\n\n // Verify token\n try {\n const payload = jwt.verify(token, publicKey, {\n algorithms: ['RS256'],\n }) as T;\n console.log(`[TokenVerifier] ✅ Token verified successfully`);\n return payload;\n } catch (error) {\n console.error(\n `[TokenVerifier] ❌ JWT verification failed: ${error instanceof Error ? error.message : String(error)}`\n );\n throw error;\n }\n }\n\n /**\n * Clear cache (useful for testing or key rotation)\n */\n clearCache(secretKeyOrUrl?: string): void {\n if (secretKeyOrUrl) {\n this.cache.delete(secretKeyOrUrl);\n } else {\n this.cache.clear();\n }\n }\n}\n\n/**\n * Convenience function to verify a token\n */\nexport async function verifyToken<T = unknown>(options: VerifyTokenOptions): Promise<T> {\n const verifier = new TokenVerifier();\n return verifier.verifyToken<T>(options);\n}\n"],"mappings":";AAAA,SAAS,aAAa,kBAAkB;AACxC,OAAgE;;;ACAhE,YAAY,YAAY;AACxB,YAAY,SAAS;AAiCd,IAAM,gBAAN,MAAoB;AAAA,EACR,QAAQ,oBAAI,IAAuB;AAAA,EACnC;AAAA,EACA;AAAA,EAEjB,YAAY,SAAgC;AAC1C,SAAK,WAAW,SAAS,YAAY,KAAK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