@mastra/auth-okta 0.2.3 → 0.2.4
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/index.cjs +30 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +30 -9
- package/dist/index.js.map +1 -1
- package/dist/rbac-provider.d.ts +2 -1
- package/dist/rbac-provider.d.ts.map +1 -1
- package/package.json +4 -5
package/dist/index.cjs
CHANGED
|
@@ -1,28 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region \0rolldown/runtime.js
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: ((k) => from[k]).bind(null, key),
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
-
value: mod,
|
|
21
|
-
enumerable: true
|
|
22
|
-
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
24
|
-
let _okta_okta_sdk_nodejs = require("@okta/okta-sdk-nodejs");
|
|
25
|
-
_okta_okta_sdk_nodejs = __toESM(_okta_okta_sdk_nodejs, 1);
|
|
26
2
|
let lru_cache = require("lru-cache");
|
|
27
3
|
let jose = require("jose");
|
|
28
4
|
//#region ../../packages/_internals/auth/dist/ee-btY6vXIW.js
|
|
@@ -136,11 +112,23 @@ function resolvePermissionsFromMapping(roles, mapping) {
|
|
|
136
112
|
*/
|
|
137
113
|
//#endregion
|
|
138
114
|
//#region src/rbac-provider.ts
|
|
139
|
-
const { Client } = _okta_okta_sdk_nodejs.default;
|
|
140
115
|
/** Default cache TTL in milliseconds (60 seconds) */
|
|
141
116
|
const DEFAULT_CACHE_TTL_MS = 60 * 1e3;
|
|
142
117
|
/** Default max cache size (number of users) */
|
|
143
118
|
const DEFAULT_CACHE_MAX_SIZE = 1e3;
|
|
119
|
+
/** Page size for the Okta list-user-groups call (Okta max is 200) */
|
|
120
|
+
const GROUPS_PAGE_LIMIT = 200;
|
|
121
|
+
/**
|
|
122
|
+
* Return the rel="next" URL from an Okta Link header, if any.
|
|
123
|
+
* Okta paginates with Link headers: `<https://...>; rel="next"`.
|
|
124
|
+
*/
|
|
125
|
+
function getNextLink(linkHeader) {
|
|
126
|
+
if (!linkHeader) return void 0;
|
|
127
|
+
for (const part of linkHeader.split(",")) {
|
|
128
|
+
const match = part.match(/<([^>]+)>\s*;\s*rel="?next"?/);
|
|
129
|
+
if (match) return match[1];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
144
132
|
/**
|
|
145
133
|
* Okta RBAC provider that maps Okta groups to Mastra permissions.
|
|
146
134
|
*
|
|
@@ -186,7 +174,8 @@ const DEFAULT_CACHE_MAX_SIZE = 1e3;
|
|
|
186
174
|
* ```
|
|
187
175
|
*/
|
|
188
176
|
var MastraRBACOkta = class {
|
|
189
|
-
|
|
177
|
+
orgUrl;
|
|
178
|
+
apiToken;
|
|
190
179
|
options;
|
|
191
180
|
/**
|
|
192
181
|
* Single cache for roles (the expensive Okta API call).
|
|
@@ -212,10 +201,8 @@ var MastraRBACOkta = class {
|
|
|
212
201
|
const apiToken = options.apiToken ?? process.env.OKTA_API_TOKEN;
|
|
213
202
|
if (!domain) throw new Error("Okta domain is required. Provide it in the options or set OKTA_DOMAIN environment variable.");
|
|
214
203
|
if (!apiToken) throw new Error("Okta API token is required for RBAC. Provide it in the options or set OKTA_API_TOKEN environment variable.");
|
|
215
|
-
this.
|
|
216
|
-
|
|
217
|
-
token: apiToken
|
|
218
|
-
});
|
|
204
|
+
this.orgUrl = `https://${domain}`;
|
|
205
|
+
this.apiToken = apiToken;
|
|
219
206
|
this.options = options;
|
|
220
207
|
this.rolesCache = new lru_cache.LRUCache({
|
|
221
208
|
max: options.cache?.maxSize ?? DEFAULT_CACHE_MAX_SIZE,
|
|
@@ -258,9 +245,20 @@ var MastraRBACOkta = class {
|
|
|
258
245
|
* Errors propagate to the caller so the cache eviction in getRoles() works.
|
|
259
246
|
*/
|
|
260
247
|
async fetchGroupsFromOkta(userId) {
|
|
261
|
-
const groups = await this.oktaClient.userApi.listUserGroups({ userId });
|
|
262
248
|
const groupNames = [];
|
|
263
|
-
|
|
249
|
+
const origin = new URL(this.orgUrl).origin;
|
|
250
|
+
let url = `${this.orgUrl}/api/v1/users/${encodeURIComponent(userId)}/groups?limit=${GROUPS_PAGE_LIMIT}`;
|
|
251
|
+
while (url) {
|
|
252
|
+
const response = await fetch(url, { headers: {
|
|
253
|
+
Accept: "application/json",
|
|
254
|
+
Authorization: `SSWS ${this.apiToken}`
|
|
255
|
+
} });
|
|
256
|
+
if (!response.ok) throw new Error(`Okta list user groups request failed with status ${response.status}`);
|
|
257
|
+
const groups = await response.json();
|
|
258
|
+
for (const group of groups) if (group?.profile?.name) groupNames.push(group.profile.name);
|
|
259
|
+
const next = getNextLink(response.headers.get("link"));
|
|
260
|
+
url = next && new URL(next).origin === origin ? next : void 0;
|
|
261
|
+
}
|
|
264
262
|
return groupNames;
|
|
265
263
|
}
|
|
266
264
|
/**
|