@mastra/auth-okta 0.2.3 → 0.2.4-alpha.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/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import pkg from "@okta/okta-sdk-nodejs";
2
1
  import { LRUCache } from "lru-cache";
3
2
  import { createRemoteJWKSet, jwtVerify } from "jose";
4
3
  //#region ../../packages/_internals/auth/dist/ee-btY6vXIW.js
@@ -112,11 +111,23 @@ function resolvePermissionsFromMapping(roles, mapping) {
112
111
  */
113
112
  //#endregion
114
113
  //#region src/rbac-provider.ts
115
- const { Client } = pkg;
116
114
  /** Default cache TTL in milliseconds (60 seconds) */
117
115
  const DEFAULT_CACHE_TTL_MS = 60 * 1e3;
118
116
  /** Default max cache size (number of users) */
119
117
  const DEFAULT_CACHE_MAX_SIZE = 1e3;
118
+ /** Page size for the Okta list-user-groups call (Okta max is 200) */
119
+ const GROUPS_PAGE_LIMIT = 200;
120
+ /**
121
+ * Return the rel="next" URL from an Okta Link header, if any.
122
+ * Okta paginates with Link headers: `<https://...>; rel="next"`.
123
+ */
124
+ function getNextLink(linkHeader) {
125
+ if (!linkHeader) return void 0;
126
+ for (const part of linkHeader.split(",")) {
127
+ const match = part.match(/<([^>]+)>\s*;\s*rel="?next"?/);
128
+ if (match) return match[1];
129
+ }
130
+ }
120
131
  /**
121
132
  * Okta RBAC provider that maps Okta groups to Mastra permissions.
122
133
  *
@@ -162,7 +173,8 @@ const DEFAULT_CACHE_MAX_SIZE = 1e3;
162
173
  * ```
163
174
  */
164
175
  var MastraRBACOkta = class {
165
- oktaClient;
176
+ orgUrl;
177
+ apiToken;
166
178
  options;
167
179
  /**
168
180
  * Single cache for roles (the expensive Okta API call).
@@ -188,10 +200,8 @@ var MastraRBACOkta = class {
188
200
  const apiToken = options.apiToken ?? process.env.OKTA_API_TOKEN;
189
201
  if (!domain) throw new Error("Okta domain is required. Provide it in the options or set OKTA_DOMAIN environment variable.");
190
202
  if (!apiToken) throw new Error("Okta API token is required for RBAC. Provide it in the options or set OKTA_API_TOKEN environment variable.");
191
- this.oktaClient = new Client({
192
- orgUrl: `https://${domain}`,
193
- token: apiToken
194
- });
203
+ this.orgUrl = `https://${domain}`;
204
+ this.apiToken = apiToken;
195
205
  this.options = options;
196
206
  this.rolesCache = new LRUCache({
197
207
  max: options.cache?.maxSize ?? DEFAULT_CACHE_MAX_SIZE,
@@ -234,9 +244,20 @@ var MastraRBACOkta = class {
234
244
  * Errors propagate to the caller so the cache eviction in getRoles() works.
235
245
  */
236
246
  async fetchGroupsFromOkta(userId) {
237
- const groups = await this.oktaClient.userApi.listUserGroups({ userId });
238
247
  const groupNames = [];
239
- for await (const group of groups) if (group && group.profile?.name) groupNames.push(group.profile.name);
248
+ const origin = new URL(this.orgUrl).origin;
249
+ let url = `${this.orgUrl}/api/v1/users/${encodeURIComponent(userId)}/groups?limit=${GROUPS_PAGE_LIMIT}`;
250
+ while (url) {
251
+ const response = await fetch(url, { headers: {
252
+ Accept: "application/json",
253
+ Authorization: `SSWS ${this.apiToken}`
254
+ } });
255
+ if (!response.ok) throw new Error(`Okta list user groups request failed with status ${response.status}`);
256
+ const groups = await response.json();
257
+ for (const group of groups) if (group?.profile?.name) groupNames.push(group.profile.name);
258
+ const next = getNextLink(response.headers.get("link"));
259
+ url = next && new URL(next).origin === origin ? next : void 0;
260
+ }
240
261
  return groupNames;
241
262
  }
242
263
  /**