@mastra/auth-studio 0.0.0-a2a-vnext-20260424123427
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 +93 -0
- package/LICENSE.md +30 -0
- package/dist/index.cjs +340 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +112 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +337 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @mastra/auth-studio
|
|
2
|
+
|
|
3
|
+
## 0.0.0-a2a-vnext-20260424123427
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`092271d`](https://github.com/mastra-ai/mastra/commit/092271d86af4cbe0d70cbf32709dd99b58acd3dd)]:
|
|
8
|
+
- @mastra/core@0.0.0-a2a-vnext-20260424123427
|
|
9
|
+
|
|
10
|
+
## 1.2.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Fix session refresh for studio-deployed instances. Sessions now properly refresh when expired, preventing users from being logged out every 5 minutes. ([#15024](https://github.com/mastra-ai/mastra/pull/15024))
|
|
15
|
+
|
|
16
|
+
- Fix Bearer token authentication to extract role from /auth/verify response. Previously, CLI tokens created via `mastra auth token create` would fail permission checks because the role was not being extracted, causing MastraRBACStudio to fall back to empty default permissions. ([#15075](https://github.com/mastra-ai/mastra/pull/15075))
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`f32b9e1`](https://github.com/mastra-ai/mastra/commit/f32b9e115a3c754d1c8cfa3f4256fba87b09cfb7), [`7d6f521`](https://github.com/mastra-ai/mastra/commit/7d6f52164d0cca099f0b07cb2bba334360f1c8ab), [`a50d220`](https://github.com/mastra-ai/mastra/commit/a50d220b01ecbc5644d489a3d446c3bd4ab30245), [`665477b`](https://github.com/mastra-ai/mastra/commit/665477bc104fd52cfef8e7610d7664781a70c220), [`4cc2755`](https://github.com/mastra-ai/mastra/commit/4cc2755a7194cb08720ff2ab4dffb4b4a5103dfd), [`ac7baf6`](https://github.com/mastra-ai/mastra/commit/ac7baf66ef1db15e03975ef4ebb02724f015a391), [`ed425d7`](https://github.com/mastra-ai/mastra/commit/ed425d78e7c66cbda8209fee910856f98c6c6b82), [`1371703`](https://github.com/mastra-ai/mastra/commit/1371703835080450ef3f9aea58059a95d0da2e5a), [`0df8321`](https://github.com/mastra-ai/mastra/commit/0df832196eeb2450ab77ce887e8553abdd44c5a6), [`98f8a8b`](https://github.com/mastra-ai/mastra/commit/98f8a8bdf5761b9982f3ad3acbe7f1cc3efa71f3), [`ba6f7e9`](https://github.com/mastra-ai/mastra/commit/ba6f7e9086d8281393f2acae60fda61de3bff1f9), [`7eb2596`](https://github.com/mastra-ai/mastra/commit/7eb25960d607e07468c9a10c5437abd2deaf1e9a), [`1805ddc`](https://github.com/mastra-ai/mastra/commit/1805ddc9c9b3b14b63749735a13c05a45af43a80), [`fff91cf`](https://github.com/mastra-ai/mastra/commit/fff91cf914de0e731578aacebffdeebef82f0440), [`61109b3`](https://github.com/mastra-ai/mastra/commit/61109b34feb0e38d54bee4b8ca83eb7345b1d557), [`33f1ead`](https://github.com/mastra-ai/mastra/commit/33f1eadfa19c86953f593478e5fa371093b33779)]:
|
|
19
|
+
- @mastra/core@1.23.0
|
|
20
|
+
|
|
21
|
+
## 1.2.1-alpha.1
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Fix Bearer token authentication to extract role from /auth/verify response. Previously, CLI tokens created via `mastra auth token create` would fail permission checks because the role was not being extracted, causing MastraRBACStudio to fall back to empty default permissions. ([#15075](https://github.com/mastra-ai/mastra/pull/15075))
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [[`1371703`](https://github.com/mastra-ai/mastra/commit/1371703835080450ef3f9aea58059a95d0da2e5a), [`98f8a8b`](https://github.com/mastra-ai/mastra/commit/98f8a8bdf5761b9982f3ad3acbe7f1cc3efa71f3)]:
|
|
28
|
+
- @mastra/core@1.23.0-alpha.5
|
|
29
|
+
|
|
30
|
+
## 1.2.1-alpha.0
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Fix session refresh for studio-deployed instances. Sessions now properly refresh when expired, preventing users from being logged out every 5 minutes. ([#15024](https://github.com/mastra-ai/mastra/pull/15024))
|
|
35
|
+
|
|
36
|
+
- Updated dependencies [[`ed425d7`](https://github.com/mastra-ai/mastra/commit/ed425d78e7c66cbda8209fee910856f98c6c6b82), [`ba6f7e9`](https://github.com/mastra-ai/mastra/commit/ba6f7e9086d8281393f2acae60fda61de3bff1f9), [`7eb2596`](https://github.com/mastra-ai/mastra/commit/7eb25960d607e07468c9a10c5437abd2deaf1e9a)]:
|
|
37
|
+
- @mastra/core@1.23.0-alpha.0
|
|
38
|
+
|
|
39
|
+
## 1.2.0
|
|
40
|
+
|
|
41
|
+
### Minor Changes
|
|
42
|
+
|
|
43
|
+
- Add configurable cookie domain support ([#14285](https://github.com/mastra-ai/mastra/pull/14285))
|
|
44
|
+
- Add `cookieDomain` option to `MastraAuthStudioOptions` for explicit configuration
|
|
45
|
+
- Support `MASTRA_COOKIE_DOMAIN` environment variable as fallback
|
|
46
|
+
- Use hostname-based detection for auto-detecting `.mastra.ai` domain (prevents false positives from malicious URLs)
|
|
47
|
+
- Maintain backward compatibility with existing `.mastra.ai` auto-detection
|
|
48
|
+
|
|
49
|
+
### Patch Changes
|
|
50
|
+
|
|
51
|
+
- Updated dependencies [[`51970b3`](https://github.com/mastra-ai/mastra/commit/51970b3828494d59a8dd4df143b194d37d31e3f5), [`4444280`](https://github.com/mastra-ai/mastra/commit/444428094253e916ec077e66284e685fde67021e), [`085e371`](https://github.com/mastra-ai/mastra/commit/085e3718a7d0fe9a210fe7dd1c867b9bdfe8d16b), [`b77aa19`](https://github.com/mastra-ai/mastra/commit/b77aa1981361c021f2c881bee8f0c703687f00da), [`dbb879a`](https://github.com/mastra-ai/mastra/commit/dbb879af0b809c668e9b3a9d8bac97d806caa267), [`8b4ce84`](https://github.com/mastra-ai/mastra/commit/8b4ce84aed0808b9805cc4fd7147c1f8a2ef7a36), [`8d4cfe6`](https://github.com/mastra-ai/mastra/commit/8d4cfe6b9a7157d3876206227ec9f04cde6dbc4a), [`dd6ca1c`](https://github.com/mastra-ai/mastra/commit/dd6ca1cdea3b8b6182f4cf61df41070ba0cc0deb), [`ce26fe2`](https://github.com/mastra-ai/mastra/commit/ce26fe2166dd90254f8bee5776e55977143e97de), [`68a019d`](https://github.com/mastra-ai/mastra/commit/68a019d30d22251ddd628a2947d60215c03c350a), [`4cb4edf`](https://github.com/mastra-ai/mastra/commit/4cb4edf3c909d197ec356c1790d13270514ffef6), [`8de3555`](https://github.com/mastra-ai/mastra/commit/8de355572c6fd838f863a3e7e6fe24d0947b774f), [`b26307f`](https://github.com/mastra-ai/mastra/commit/b26307f050df39629511b0e831b8fc26973ce8b1), [`68a019d`](https://github.com/mastra-ai/mastra/commit/68a019d30d22251ddd628a2947d60215c03c350a)]:
|
|
52
|
+
- @mastra/core@1.14.0
|
|
53
|
+
|
|
54
|
+
## 1.2.0-alpha.0
|
|
55
|
+
|
|
56
|
+
### Minor Changes
|
|
57
|
+
|
|
58
|
+
- Add configurable cookie domain support ([#14285](https://github.com/mastra-ai/mastra/pull/14285))
|
|
59
|
+
- Add `cookieDomain` option to `MastraAuthStudioOptions` for explicit configuration
|
|
60
|
+
- Support `MASTRA_COOKIE_DOMAIN` environment variable as fallback
|
|
61
|
+
- Use hostname-based detection for auto-detecting `.mastra.ai` domain (prevents false positives from malicious URLs)
|
|
62
|
+
- Maintain backward compatibility with existing `.mastra.ai` auto-detection
|
|
63
|
+
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- Updated dependencies [[`4444280`](https://github.com/mastra-ai/mastra/commit/444428094253e916ec077e66284e685fde67021e), [`dbb879a`](https://github.com/mastra-ai/mastra/commit/dbb879af0b809c668e9b3a9d8bac97d806caa267), [`8de3555`](https://github.com/mastra-ai/mastra/commit/8de355572c6fd838f863a3e7e6fe24d0947b774f)]:
|
|
67
|
+
- @mastra/core@1.14.0-alpha.2
|
|
68
|
+
|
|
69
|
+
## 1.1.0
|
|
70
|
+
|
|
71
|
+
### Minor Changes
|
|
72
|
+
|
|
73
|
+
- Added `@mastra/auth-studio` — an auth provider for deployed Mastra Studio instances that proxies authentication through the Mastra shared API. ([#13163](https://github.com/mastra-ai/mastra/pull/13163))
|
|
74
|
+
|
|
75
|
+
Deployed instances need no secrets — all WorkOS authentication is handled by the shared API. The package provides SSO login/callback flows, session management via sealed cookies, RBAC with organization-scoped permissions, and automatic forced account picker on deploy logins.
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- Updated dependencies [[`504fc8b`](https://github.com/mastra-ai/mastra/commit/504fc8b9d0ddab717577ad3bf9c95ea4bd5377bd), [`f9c150b`](https://github.com/mastra-ai/mastra/commit/f9c150b7595ad05ad9cc9a11098e2944361e8c22), [`88de7e8`](https://github.com/mastra-ai/mastra/commit/88de7e8dfe4b7e1951a9e441bb33136e705ce24e), [`edee4b3`](https://github.com/mastra-ai/mastra/commit/edee4b37dff0af515fc7cc0e8d71ee39e6a762f0), [`3790c75`](https://github.com/mastra-ai/mastra/commit/3790c7578cc6a47d854eb12d89e6b1912867fe29), [`e7a235b`](https://github.com/mastra-ai/mastra/commit/e7a235be6472e0c870ed6c791ddb17c492dc188b), [`d51d298`](https://github.com/mastra-ai/mastra/commit/d51d298953967aab1f58ec965b644d109214f085), [`6dbeeb9`](https://github.com/mastra-ai/mastra/commit/6dbeeb94a8b1eebb727300d1a98961f882180794), [`d5f0d8d`](https://github.com/mastra-ai/mastra/commit/d5f0d8d6a03e515ddaa9b5da19b7e44b8357b07b), [`09c3b18`](https://github.com/mastra-ai/mastra/commit/09c3b1802ff14e243a8a8baea327440bc8cc2e32), [`b896379`](https://github.com/mastra-ai/mastra/commit/b8963791c6afa79484645fcec596a201f936b9a2), [`85c84eb`](https://github.com/mastra-ai/mastra/commit/85c84ebb78aebfcba9d209c8e152b16d7a00cb71), [`a89272a`](https://github.com/mastra-ai/mastra/commit/a89272a5d71939b9fcd284e6a6dc1dd091a6bdcf), [`ee9c8df`](https://github.com/mastra-ai/mastra/commit/ee9c8df644f19d055af5f496bf4942705f5a47b7), [`77b4a25`](https://github.com/mastra-ai/mastra/commit/77b4a254e51907f8ff3a3ba95596a18e93ae4b35), [`276246e`](https://github.com/mastra-ai/mastra/commit/276246e0b9066a1ea48bbc70df84dbe528daaf99), [`08ecfdb`](https://github.com/mastra-ai/mastra/commit/08ecfdbdad6fb8285deef86a034bdf4a6047cfca), [`d5f628c`](https://github.com/mastra-ai/mastra/commit/d5f628ca86c6f6f3ff1035d52f635df32dd81cab), [`524c0f3`](https://github.com/mastra-ai/mastra/commit/524c0f3c434c3d9d18f66338dcef383d6161b59c), [`c18a0e9`](https://github.com/mastra-ai/mastra/commit/c18a0e9cef1e4ca004b2963d35e4cfc031971eac), [`4bd21ea`](https://github.com/mastra-ai/mastra/commit/4bd21ea43d44d0a0427414fc047577f9f0aa3bec), [`115a7a4`](https://github.com/mastra-ai/mastra/commit/115a7a47db5e9896fec12ae6507501adb9ec89bf), [`22a48ae`](https://github.com/mastra-ai/mastra/commit/22a48ae2513eb54d8d79dad361fddbca97a155e8), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9311c17`](https://github.com/mastra-ai/mastra/commit/9311c17d7a0640d9c4da2e71b814dc67c57c6369), [`7edf78f`](https://github.com/mastra-ai/mastra/commit/7edf78f80422c43e84585f08ba11df0d4d0b73c5), [`1c4221c`](https://github.com/mastra-ai/mastra/commit/1c4221cf6032ec98d0e094d4ee11da3e48490d96), [`d25b9ea`](https://github.com/mastra-ai/mastra/commit/d25b9eabd400167255a97b690ffbc4ee4097ded5), [`fe1ce5c`](https://github.com/mastra-ai/mastra/commit/fe1ce5c9211c03d561606fda95cbfe7df1d9a9b5), [`b03c0e0`](https://github.com/mastra-ai/mastra/commit/b03c0e0389a799523929a458b0509c9e4244d562), [`0a8366b`](https://github.com/mastra-ai/mastra/commit/0a8366b0a692fcdde56c4d526e4cf03c502ae4ac), [`85664e9`](https://github.com/mastra-ai/mastra/commit/85664e9fd857320fbc245e301f764f45f66f32a3), [`bc79650`](https://github.com/mastra-ai/mastra/commit/bc796500c6e0334faa158a96077e3fb332274869), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`3a3a59e`](https://github.com/mastra-ai/mastra/commit/3a3a59e8ffaa6a985fe3d9a126a3f5ade11a6724), [`3108d4e`](https://github.com/mastra-ai/mastra/commit/3108d4e649c9fddbf03253a6feeb388a5fa9fa5a), [`0c33b2c`](https://github.com/mastra-ai/mastra/commit/0c33b2c9db537f815e1c59e2c898ffce2e395a79), [`191e5bd`](https://github.com/mastra-ai/mastra/commit/191e5bd29b82f5bda35243945790da7bc7b695c2), [`f77cd94`](https://github.com/mastra-ai/mastra/commit/f77cd94c44eabed490384e7d19232a865e13214c), [`e8135c7`](https://github.com/mastra-ai/mastra/commit/e8135c7e300dac5040670eec7eab896ac6092e30), [`daca48f`](https://github.com/mastra-ai/mastra/commit/daca48f0fb17b7ae0b62a2ac40cf0e491b2fd0b7), [`257d14f`](https://github.com/mastra-ai/mastra/commit/257d14faca5931f2e4186fc165b6f0b1f915deee), [`352f25d`](https://github.com/mastra-ai/mastra/commit/352f25da316b24cdd5b410fd8dddf6a8b763da2a), [`93477d0`](https://github.com/mastra-ai/mastra/commit/93477d0769b8a13ea5ed73d508d967fb23eaeed9), [`31c78b3`](https://github.com/mastra-ai/mastra/commit/31c78b3eb28f58a8017f1dcc795c33214d87feac), [`0bc0720`](https://github.com/mastra-ai/mastra/commit/0bc07201095791858087cc56f353fcd65e87ab54), [`36516ac`](https://github.com/mastra-ai/mastra/commit/36516aca1021cbeb42e74751b46a2614101f37c8), [`e947652`](https://github.com/mastra-ai/mastra/commit/e9476527fdecb4449e54570e80dfaf8466901254), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`ec248f6`](https://github.com/mastra-ai/mastra/commit/ec248f6b56e8a037c066c49b2178e2507471d988)]:
|
|
80
|
+
- @mastra/core@1.9.0
|
|
81
|
+
|
|
82
|
+
## 1.1.0-alpha.0
|
|
83
|
+
|
|
84
|
+
### Minor Changes
|
|
85
|
+
|
|
86
|
+
- Added `@mastra/auth-studio` — an auth provider for deployed Mastra Studio instances that proxies authentication through the Mastra shared API. ([#13163](https://github.com/mastra-ai/mastra/pull/13163))
|
|
87
|
+
|
|
88
|
+
Deployed instances need no secrets — all WorkOS authentication is handled by the shared API. The package provides SSO login/callback flows, session management via sealed cookies, RBAC with organization-scoped permissions, and automatic forced account picker on deploy logins.
|
|
89
|
+
|
|
90
|
+
### Patch Changes
|
|
91
|
+
|
|
92
|
+
- Updated dependencies [[`504fc8b`](https://github.com/mastra-ai/mastra/commit/504fc8b9d0ddab717577ad3bf9c95ea4bd5377bd), [`f9c150b`](https://github.com/mastra-ai/mastra/commit/f9c150b7595ad05ad9cc9a11098e2944361e8c22), [`88de7e8`](https://github.com/mastra-ai/mastra/commit/88de7e8dfe4b7e1951a9e441bb33136e705ce24e), [`edee4b3`](https://github.com/mastra-ai/mastra/commit/edee4b37dff0af515fc7cc0e8d71ee39e6a762f0), [`3790c75`](https://github.com/mastra-ai/mastra/commit/3790c7578cc6a47d854eb12d89e6b1912867fe29), [`e7a235b`](https://github.com/mastra-ai/mastra/commit/e7a235be6472e0c870ed6c791ddb17c492dc188b), [`d51d298`](https://github.com/mastra-ai/mastra/commit/d51d298953967aab1f58ec965b644d109214f085), [`6dbeeb9`](https://github.com/mastra-ai/mastra/commit/6dbeeb94a8b1eebb727300d1a98961f882180794), [`d5f0d8d`](https://github.com/mastra-ai/mastra/commit/d5f0d8d6a03e515ddaa9b5da19b7e44b8357b07b), [`09c3b18`](https://github.com/mastra-ai/mastra/commit/09c3b1802ff14e243a8a8baea327440bc8cc2e32), [`b896379`](https://github.com/mastra-ai/mastra/commit/b8963791c6afa79484645fcec596a201f936b9a2), [`85c84eb`](https://github.com/mastra-ai/mastra/commit/85c84ebb78aebfcba9d209c8e152b16d7a00cb71), [`a89272a`](https://github.com/mastra-ai/mastra/commit/a89272a5d71939b9fcd284e6a6dc1dd091a6bdcf), [`ee9c8df`](https://github.com/mastra-ai/mastra/commit/ee9c8df644f19d055af5f496bf4942705f5a47b7), [`77b4a25`](https://github.com/mastra-ai/mastra/commit/77b4a254e51907f8ff3a3ba95596a18e93ae4b35), [`276246e`](https://github.com/mastra-ai/mastra/commit/276246e0b9066a1ea48bbc70df84dbe528daaf99), [`08ecfdb`](https://github.com/mastra-ai/mastra/commit/08ecfdbdad6fb8285deef86a034bdf4a6047cfca), [`d5f628c`](https://github.com/mastra-ai/mastra/commit/d5f628ca86c6f6f3ff1035d52f635df32dd81cab), [`524c0f3`](https://github.com/mastra-ai/mastra/commit/524c0f3c434c3d9d18f66338dcef383d6161b59c), [`c18a0e9`](https://github.com/mastra-ai/mastra/commit/c18a0e9cef1e4ca004b2963d35e4cfc031971eac), [`4bd21ea`](https://github.com/mastra-ai/mastra/commit/4bd21ea43d44d0a0427414fc047577f9f0aa3bec), [`115a7a4`](https://github.com/mastra-ai/mastra/commit/115a7a47db5e9896fec12ae6507501adb9ec89bf), [`22a48ae`](https://github.com/mastra-ai/mastra/commit/22a48ae2513eb54d8d79dad361fddbca97a155e8), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9311c17`](https://github.com/mastra-ai/mastra/commit/9311c17d7a0640d9c4da2e71b814dc67c57c6369), [`7edf78f`](https://github.com/mastra-ai/mastra/commit/7edf78f80422c43e84585f08ba11df0d4d0b73c5), [`1c4221c`](https://github.com/mastra-ai/mastra/commit/1c4221cf6032ec98d0e094d4ee11da3e48490d96), [`d25b9ea`](https://github.com/mastra-ai/mastra/commit/d25b9eabd400167255a97b690ffbc4ee4097ded5), [`fe1ce5c`](https://github.com/mastra-ai/mastra/commit/fe1ce5c9211c03d561606fda95cbfe7df1d9a9b5), [`b03c0e0`](https://github.com/mastra-ai/mastra/commit/b03c0e0389a799523929a458b0509c9e4244d562), [`0a8366b`](https://github.com/mastra-ai/mastra/commit/0a8366b0a692fcdde56c4d526e4cf03c502ae4ac), [`85664e9`](https://github.com/mastra-ai/mastra/commit/85664e9fd857320fbc245e301f764f45f66f32a3), [`bc79650`](https://github.com/mastra-ai/mastra/commit/bc796500c6e0334faa158a96077e3fb332274869), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`3a3a59e`](https://github.com/mastra-ai/mastra/commit/3a3a59e8ffaa6a985fe3d9a126a3f5ade11a6724), [`3108d4e`](https://github.com/mastra-ai/mastra/commit/3108d4e649c9fddbf03253a6feeb388a5fa9fa5a), [`0c33b2c`](https://github.com/mastra-ai/mastra/commit/0c33b2c9db537f815e1c59e2c898ffce2e395a79), [`191e5bd`](https://github.com/mastra-ai/mastra/commit/191e5bd29b82f5bda35243945790da7bc7b695c2), [`f77cd94`](https://github.com/mastra-ai/mastra/commit/f77cd94c44eabed490384e7d19232a865e13214c), [`e8135c7`](https://github.com/mastra-ai/mastra/commit/e8135c7e300dac5040670eec7eab896ac6092e30), [`daca48f`](https://github.com/mastra-ai/mastra/commit/daca48f0fb17b7ae0b62a2ac40cf0e491b2fd0b7), [`257d14f`](https://github.com/mastra-ai/mastra/commit/257d14faca5931f2e4186fc165b6f0b1f915deee), [`352f25d`](https://github.com/mastra-ai/mastra/commit/352f25da316b24cdd5b410fd8dddf6a8b763da2a), [`93477d0`](https://github.com/mastra-ai/mastra/commit/93477d0769b8a13ea5ed73d508d967fb23eaeed9), [`31c78b3`](https://github.com/mastra-ai/mastra/commit/31c78b3eb28f58a8017f1dcc795c33214d87feac), [`0bc0720`](https://github.com/mastra-ai/mastra/commit/0bc07201095791858087cc56f353fcd65e87ab54), [`36516ac`](https://github.com/mastra-ai/mastra/commit/36516aca1021cbeb42e74751b46a2614101f37c8), [`e947652`](https://github.com/mastra-ai/mastra/commit/e9476527fdecb4449e54570e80dfaf8466901254), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`ec248f6`](https://github.com/mastra-ai/mastra/commit/ec248f6b56e8a037c066c49b2178e2507471d988)]:
|
|
93
|
+
- @mastra/core@1.9.0-alpha.0
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
- All content that resides under any directory named "ee/" within this
|
|
4
|
+
repository, including but not limited to:
|
|
5
|
+
- `packages/core/src/auth/ee/`
|
|
6
|
+
- `packages/server/src/server/auth/ee/`
|
|
7
|
+
is licensed under the license defined in `ee/LICENSE`.
|
|
8
|
+
|
|
9
|
+
- All third-party components incorporated into the Mastra Software are
|
|
10
|
+
licensed under the original license provided by the owner of the
|
|
11
|
+
applicable component.
|
|
12
|
+
|
|
13
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
14
|
+
available under the "Apache License 2.0" as defined below.
|
|
15
|
+
|
|
16
|
+
# Apache License 2.0
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
19
|
+
|
|
20
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
you may not use this file except in compliance with the License.
|
|
22
|
+
You may obtain a copy of the License at
|
|
23
|
+
|
|
24
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
+
|
|
26
|
+
Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
See the License for the specific language governing permissions and
|
|
30
|
+
limitations under the License.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ee = require('@mastra/core/auth/ee');
|
|
4
|
+
var server = require('@mastra/core/server');
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
var COOKIE_NAME = "wos-session";
|
|
8
|
+
var MastraAuthStudio = class extends server.MastraAuthProvider {
|
|
9
|
+
isMastraCloudAuth = true;
|
|
10
|
+
sharedApiUrl;
|
|
11
|
+
organizationId;
|
|
12
|
+
useProductionCookies;
|
|
13
|
+
cookieDomain;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
super({ name: "mastra-studio", ...options });
|
|
16
|
+
this.sharedApiUrl = options?.sharedApiUrl || process.env.MASTRA_SHARED_API_URL || "http://localhost:3010/v1";
|
|
17
|
+
this.organizationId = options?.organizationId || process.env.MASTRA_ORGANIZATION_ID;
|
|
18
|
+
if (this.sharedApiUrl.endsWith("/")) {
|
|
19
|
+
this.sharedApiUrl = this.sharedApiUrl.slice(0, -1);
|
|
20
|
+
}
|
|
21
|
+
this.cookieDomain = options?.cookieDomain || process.env.MASTRA_COOKIE_DOMAIN;
|
|
22
|
+
let autoDetectMastraAi = false;
|
|
23
|
+
try {
|
|
24
|
+
const hostname = new URL(this.sharedApiUrl).hostname.toLowerCase();
|
|
25
|
+
autoDetectMastraAi = hostname === "mastra.ai" || hostname.endsWith(".mastra.ai");
|
|
26
|
+
} catch {
|
|
27
|
+
autoDetectMastraAi = false;
|
|
28
|
+
}
|
|
29
|
+
this.useProductionCookies = !!this.cookieDomain || autoDetectMastraAi;
|
|
30
|
+
if (!this.cookieDomain && autoDetectMastraAi) {
|
|
31
|
+
this.cookieDomain = ".mastra.ai";
|
|
32
|
+
}
|
|
33
|
+
if (options) {
|
|
34
|
+
this.registerOptions(options);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// MastraAuthProvider abstract methods
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
/**
|
|
41
|
+
* Authenticate an incoming request by forwarding the sealed session cookie
|
|
42
|
+
* to the shared API's /auth/me endpoint, or a Bearer token to /auth/verify.
|
|
43
|
+
*/
|
|
44
|
+
async authenticateToken(token, request) {
|
|
45
|
+
let user = null;
|
|
46
|
+
const cookieHeader = request?.headers?.get("Cookie");
|
|
47
|
+
const sessionCookie = parseCookie(cookieHeader, COOKIE_NAME);
|
|
48
|
+
if (sessionCookie) {
|
|
49
|
+
user = await this.verifySessionCookie(sessionCookie);
|
|
50
|
+
}
|
|
51
|
+
if (!user && token) {
|
|
52
|
+
user = await this.verifyBearerToken(token);
|
|
53
|
+
}
|
|
54
|
+
if (!user) return null;
|
|
55
|
+
if (this.organizationId && !user.memberOrgIds?.includes(this.organizationId)) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return user;
|
|
59
|
+
}
|
|
60
|
+
authorizeUser(user) {
|
|
61
|
+
return !!user?.id;
|
|
62
|
+
}
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
// ISSOProvider
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
getLoginUrl(redirectUri, state) {
|
|
67
|
+
let postLoginRedirect = "/";
|
|
68
|
+
if (state) {
|
|
69
|
+
const pipeIndex = state.indexOf("|");
|
|
70
|
+
if (pipeIndex !== -1) {
|
|
71
|
+
try {
|
|
72
|
+
postLoginRedirect = decodeURIComponent(state.slice(pipeIndex + 1));
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const params = new URLSearchParams({
|
|
78
|
+
product: "deploy",
|
|
79
|
+
redirect_uri: redirectUri,
|
|
80
|
+
post_login_redirect: postLoginRedirect,
|
|
81
|
+
// Force re-authentication so AuthKit always shows the account picker
|
|
82
|
+
prompt: "login",
|
|
83
|
+
...this.organizationId ? { organization_id: this.organizationId } : {}
|
|
84
|
+
});
|
|
85
|
+
return `${this.sharedApiUrl}/auth/login?${params.toString()}`;
|
|
86
|
+
}
|
|
87
|
+
async handleCallback(code, _state) {
|
|
88
|
+
const user = await this.verifySessionCookie(code);
|
|
89
|
+
if (!user) {
|
|
90
|
+
throw new Error("Session validation failed");
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
user,
|
|
94
|
+
tokens: {
|
|
95
|
+
accessToken: code
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
setCallbackCookieHeader(_cookieHeader) {
|
|
100
|
+
}
|
|
101
|
+
getLoginCookies() {
|
|
102
|
+
return void 0;
|
|
103
|
+
}
|
|
104
|
+
getLoginButtonConfig() {
|
|
105
|
+
return {
|
|
106
|
+
provider: "mastra-studio",
|
|
107
|
+
text: "Sign in with Mastra"
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async getLogoutUrl(_redirectUri, request) {
|
|
111
|
+
const cookieHeader = request?.headers.get("Cookie");
|
|
112
|
+
const sessionCookie = parseCookie(cookieHeader, COOKIE_NAME);
|
|
113
|
+
if (!sessionCookie) return null;
|
|
114
|
+
try {
|
|
115
|
+
const res = await fetch(`${this.sharedApiUrl}/auth/logout`, {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers: {
|
|
118
|
+
"Content-Type": "application/json",
|
|
119
|
+
Cookie: `${COOKIE_NAME}=${sessionCookie}`
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
if (res.ok) {
|
|
123
|
+
const data = await res.json();
|
|
124
|
+
return data.logoutUrl ?? null;
|
|
125
|
+
}
|
|
126
|
+
} catch {
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
// ISessionProvider
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
async createSession(userId, metadata) {
|
|
134
|
+
const now = /* @__PURE__ */ new Date();
|
|
135
|
+
return {
|
|
136
|
+
id: metadata?.accessToken || crypto.randomUUID(),
|
|
137
|
+
userId,
|
|
138
|
+
expiresAt: new Date(now.getTime() + 24 * 60 * 60 * 1e3),
|
|
139
|
+
// 24 hours
|
|
140
|
+
createdAt: now,
|
|
141
|
+
metadata
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
async validateSession(sessionId) {
|
|
145
|
+
const user = await this.verifySessionCookie(sessionId);
|
|
146
|
+
if (!user) return null;
|
|
147
|
+
const now = /* @__PURE__ */ new Date();
|
|
148
|
+
return {
|
|
149
|
+
id: sessionId,
|
|
150
|
+
userId: user.id,
|
|
151
|
+
expiresAt: new Date(now.getTime() + 24 * 60 * 60 * 1e3),
|
|
152
|
+
createdAt: now
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
async destroySession(sessionId) {
|
|
156
|
+
try {
|
|
157
|
+
await fetch(`${this.sharedApiUrl}/auth/logout`, {
|
|
158
|
+
method: "POST",
|
|
159
|
+
headers: {
|
|
160
|
+
Cookie: `${COOKIE_NAME}=${sessionId}`
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
} catch {
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async refreshSession(sessionId) {
|
|
167
|
+
try {
|
|
168
|
+
const res = await fetch(`${this.sharedApiUrl}/auth/refresh`, {
|
|
169
|
+
method: "GET",
|
|
170
|
+
headers: {
|
|
171
|
+
Cookie: `${COOKIE_NAME}=${sessionId}`
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
if (!res.ok) {
|
|
175
|
+
return this.validateSession(sessionId);
|
|
176
|
+
}
|
|
177
|
+
const setCookie = res.headers.get("Set-Cookie");
|
|
178
|
+
const newSessionId = setCookie ? parseCookieFromHeader(setCookie, COOKIE_NAME) : null;
|
|
179
|
+
if (!newSessionId) {
|
|
180
|
+
return this.validateSession(sessionId);
|
|
181
|
+
}
|
|
182
|
+
const user = await this.verifySessionCookie(newSessionId);
|
|
183
|
+
if (!user) return null;
|
|
184
|
+
const now = /* @__PURE__ */ new Date();
|
|
185
|
+
return {
|
|
186
|
+
id: newSessionId,
|
|
187
|
+
userId: user.id,
|
|
188
|
+
expiresAt: new Date(now.getTime() + 24 * 60 * 60 * 1e3),
|
|
189
|
+
createdAt: now
|
|
190
|
+
};
|
|
191
|
+
} catch {
|
|
192
|
+
return this.validateSession(sessionId);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
getSessionIdFromRequest(request) {
|
|
196
|
+
const cookieHeader = request.headers.get("Cookie");
|
|
197
|
+
return parseCookie(cookieHeader, COOKIE_NAME);
|
|
198
|
+
}
|
|
199
|
+
getSessionHeaders(session) {
|
|
200
|
+
const parts = [`${COOKIE_NAME}=${session.id}`, "HttpOnly", "SameSite=Lax", "Path=/", "Max-Age=86400"];
|
|
201
|
+
if (this.useProductionCookies && this.cookieDomain) {
|
|
202
|
+
parts.push("Secure");
|
|
203
|
+
parts.push(`Domain=${this.cookieDomain}`);
|
|
204
|
+
}
|
|
205
|
+
return { "Set-Cookie": parts.join("; ") };
|
|
206
|
+
}
|
|
207
|
+
getClearSessionHeaders() {
|
|
208
|
+
const parts = [`${COOKIE_NAME}=`, "HttpOnly", "SameSite=Lax", "Path=/", "Max-Age=0"];
|
|
209
|
+
if (this.useProductionCookies && this.cookieDomain) {
|
|
210
|
+
parts.push("Secure");
|
|
211
|
+
parts.push(`Domain=${this.cookieDomain}`);
|
|
212
|
+
}
|
|
213
|
+
return { "Set-Cookie": parts.join("; ") };
|
|
214
|
+
}
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
// IUserProvider
|
|
217
|
+
// ---------------------------------------------------------------------------
|
|
218
|
+
async getCurrentUser(request) {
|
|
219
|
+
const cookieHeader = request.headers.get("Cookie");
|
|
220
|
+
const sessionCookie = parseCookie(cookieHeader, COOKIE_NAME);
|
|
221
|
+
if (sessionCookie) {
|
|
222
|
+
return this.verifySessionCookie(sessionCookie);
|
|
223
|
+
}
|
|
224
|
+
const authHeader = request.headers.get("Authorization");
|
|
225
|
+
if (authHeader?.startsWith("Bearer ")) {
|
|
226
|
+
return this.verifyBearerToken(authHeader.slice(7));
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
async getUser(_userId) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
// ---------------------------------------------------------------------------
|
|
234
|
+
// Internal helpers
|
|
235
|
+
// ---------------------------------------------------------------------------
|
|
236
|
+
/**
|
|
237
|
+
* Forward a sealed session cookie to the shared API's /auth/me endpoint
|
|
238
|
+
* to validate it and get user info.
|
|
239
|
+
*/
|
|
240
|
+
async verifySessionCookie(sessionCookie) {
|
|
241
|
+
try {
|
|
242
|
+
const res = await fetch(`${this.sharedApiUrl}/auth/me`, {
|
|
243
|
+
headers: {
|
|
244
|
+
Cookie: `${COOKIE_NAME}=${sessionCookie}`
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
if (!res.ok) return null;
|
|
248
|
+
const data = await res.json();
|
|
249
|
+
return {
|
|
250
|
+
id: data.user.id,
|
|
251
|
+
email: data.user.email,
|
|
252
|
+
name: [data.user.firstName, data.user.lastName].filter(Boolean).join(" ") || void 0,
|
|
253
|
+
avatarUrl: data.user.profilePictureUrl,
|
|
254
|
+
organizationId: data.organizationId,
|
|
255
|
+
role: data.role,
|
|
256
|
+
permissions: data.permissions,
|
|
257
|
+
memberOrgIds: data.memberOrgIds
|
|
258
|
+
};
|
|
259
|
+
} catch {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Forward a Bearer token to the shared API's /auth/verify endpoint
|
|
265
|
+
* to validate it and get user info (used for CLI tokens).
|
|
266
|
+
*/
|
|
267
|
+
async verifyBearerToken(token) {
|
|
268
|
+
try {
|
|
269
|
+
const res = await fetch(`${this.sharedApiUrl}/auth/verify`, {
|
|
270
|
+
headers: {
|
|
271
|
+
Authorization: `Bearer ${token}`
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
if (!res.ok) return null;
|
|
275
|
+
const data = await res.json();
|
|
276
|
+
return {
|
|
277
|
+
id: data.user.id,
|
|
278
|
+
email: data.user.email,
|
|
279
|
+
name: [data.user.firstName, data.user.lastName].filter(Boolean).join(" ") || void 0,
|
|
280
|
+
organizationId: data.organizationId,
|
|
281
|
+
role: data.role,
|
|
282
|
+
memberOrgIds: data.memberOrgIds
|
|
283
|
+
};
|
|
284
|
+
} catch {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
function parseCookie(cookieHeader, name) {
|
|
290
|
+
if (!cookieHeader) return null;
|
|
291
|
+
const match = cookieHeader.match(new RegExp(`${name}=([^;]+)`));
|
|
292
|
+
return match?.[1] ?? null;
|
|
293
|
+
}
|
|
294
|
+
function parseCookieFromHeader(setCookieHeader, name) {
|
|
295
|
+
const parts = setCookieHeader.split(";");
|
|
296
|
+
if (parts.length === 0) return null;
|
|
297
|
+
const [cookieName, ...valueParts] = parts[0].split("=");
|
|
298
|
+
if (cookieName?.trim() !== name) return null;
|
|
299
|
+
return valueParts.join("=") || null;
|
|
300
|
+
}
|
|
301
|
+
var MastraRBACStudio = class {
|
|
302
|
+
options;
|
|
303
|
+
get roleMapping() {
|
|
304
|
+
return this.options.roleMapping;
|
|
305
|
+
}
|
|
306
|
+
constructor(options) {
|
|
307
|
+
this.options = options;
|
|
308
|
+
}
|
|
309
|
+
async getRoles(user) {
|
|
310
|
+
return user.role ? [user.role] : [];
|
|
311
|
+
}
|
|
312
|
+
async hasRole(user, role) {
|
|
313
|
+
const roles = await this.getRoles(user);
|
|
314
|
+
return roles.includes(role);
|
|
315
|
+
}
|
|
316
|
+
async getPermissions(user) {
|
|
317
|
+
const roles = await this.getRoles(user);
|
|
318
|
+
if (roles.length === 0) {
|
|
319
|
+
return this.options.roleMapping["_default"] ?? [];
|
|
320
|
+
}
|
|
321
|
+
return ee.resolvePermissionsFromMapping(roles, this.options.roleMapping);
|
|
322
|
+
}
|
|
323
|
+
async hasPermission(user, permission) {
|
|
324
|
+
const permissions = await this.getPermissions(user);
|
|
325
|
+
return permissions.some((p) => ee.matchesPermission(p, permission));
|
|
326
|
+
}
|
|
327
|
+
async hasAllPermissions(user, permissions) {
|
|
328
|
+
const userPermissions = await this.getPermissions(user);
|
|
329
|
+
return permissions.every((required) => userPermissions.some((p) => ee.matchesPermission(p, required)));
|
|
330
|
+
}
|
|
331
|
+
async hasAnyPermission(user, permissions) {
|
|
332
|
+
const userPermissions = await this.getPermissions(user);
|
|
333
|
+
return permissions.some((required) => userPermissions.some((p) => ee.matchesPermission(p, required)));
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
exports.MastraAuthStudio = MastraAuthStudio;
|
|
338
|
+
exports.MastraRBACStudio = MastraRBACStudio;
|
|
339
|
+
//# sourceMappingURL=index.cjs.map
|
|
340
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["MastraAuthProvider","resolvePermissionsFromMapping","matchesPermission"],"mappings":";;;;;;AAuCA,IAAM,WAAA,GAAc,aAAA;AAab,IAAM,gBAAA,GAAN,cACGA,yBAAA,CAEV;AAAA,EACW,iBAAA,GAAoB,IAAA;AAAA,EAErB,YAAA;AAAA,EACA,cAAA;AAAA,EACA,oBAAA;AAAA,EACA,YAAA;AAAA,EAER,YAAY,OAAA,EAAmC;AAC7C,IAAA,KAAA,CAAM,EAAE,IAAA,EAAM,eAAA,EAAiB,GAAG,SAAS,CAAA;AAC3C,IAA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oBAAA,CAAkB,CAAA,EAAG,QAAQ,CAAC,CAAC,CAAA;AAAA,EAC/F;AACF","file":"index.cjs","sourcesContent":["import type {\n ISSOProvider,\n ISessionProvider,\n IUserProvider,\n Session,\n SSOCallbackResult,\n SSOLoginConfig,\n} from '@mastra/core/auth';\nimport type { EEUser, IRBACProvider, RoleMapping } from '@mastra/core/auth/ee';\nimport { resolvePermissionsFromMapping, matchesPermission } from '@mastra/core/auth/ee';\nimport { MastraAuthProvider } from '@mastra/core/server';\nimport type { MastraAuthProviderOptions } from '@mastra/core/server';\n\nexport interface StudioUser extends EEUser {\n id: string;\n email?: string;\n name?: string;\n avatarUrl?: string;\n organizationId?: string;\n role?: string;\n permissions?: string[];\n /** All organization IDs the user is a member of (for cross-org access checks) */\n memberOrgIds?: string[];\n}\n\nexport interface MastraAuthStudioOptions extends MastraAuthProviderOptions<StudioUser> {\n /** Base URL of the Mastra shared API (e.g., https://api.mastra.ai/v1) */\n sharedApiUrl?: string;\n /** Organization ID that owns this deployed instance. Users not in this org are rejected. */\n organizationId?: string;\n /**\n * Cookie domain for session cookies (e.g., '.example.com').\n * When set, cookies will include Secure and Domain attributes.\n * Defaults to auto-detecting from sharedApiUrl (uses '.mastra.ai' when sharedApiUrl contains '.mastra.ai').\n * Can also be set via MASTRA_COOKIE_DOMAIN environment variable.\n */\n cookieDomain?: string;\n}\n\nconst COOKIE_NAME = 'wos-session';\n\n/**\n * Auth provider for Mastra Studio deployed instances.\n *\n * Proxies all authentication through the shared API, keeping the\n * WorkOS API key safely in the shared API. Deployed instances only\n * need the shared API URL — no secrets required.\n *\n * The shared API's sealed session cookie (`wos-session`) is set with\n * `Domain=.mastra.ai` in production, so it's included in requests\n * to deployed instances and can be forwarded for validation.\n */\nexport class MastraAuthStudio\n extends MastraAuthProvider<StudioUser>\n implements ISSOProvider<StudioUser>, ISessionProvider<Session>, IUserProvider<StudioUser>\n{\n readonly isMastraCloudAuth = true;\n\n private sharedApiUrl: string;\n private organizationId: string | undefined;\n private useProductionCookies: boolean;\n private cookieDomain: string | undefined;\n\n constructor(options?: MastraAuthStudioOptions) {\n super({ name: 'mastra-studio', ...options });\n this.sharedApiUrl = options?.sharedApiUrl || process.env.MASTRA_SHARED_API_URL || 'http://localhost:3010/v1';\n this.organizationId = options?.organizationId || process.env.MASTRA_ORGANIZATION_ID;\n\n // Strip trailing slash\n if (this.sharedApiUrl.endsWith('/')) {\n this.sharedApiUrl = this.sharedApiUrl.slice(0, -1);\n }\n\n // Cookie domain can be explicitly configured, read from env, or auto-detected from sharedApiUrl\n this.cookieDomain = options?.cookieDomain || process.env.MASTRA_COOKIE_DOMAIN;\n\n // Use production cookie settings (Secure + Domain) when:\n // 1. An explicit cookieDomain is configured, OR\n // 2. The shared API is on .mastra.ai (auto-detect default domain)\n // Use hostname-based detection to avoid false positives (e.g., api.mastra.ai.evil.com)\n let autoDetectMastraAi = false;\n try {\n const hostname = new URL(this.sharedApiUrl).hostname.toLowerCase();\n autoDetectMastraAi = hostname === 'mastra.ai' || hostname.endsWith('.mastra.ai');\n } catch {\n autoDetectMastraAi = false;\n }\n this.useProductionCookies = !!this.cookieDomain || autoDetectMastraAi;\n\n // If no explicit domain but we're on .mastra.ai, use the default domain\n if (!this.cookieDomain && autoDetectMastraAi) {\n this.cookieDomain = '.mastra.ai';\n }\n\n if (options) {\n this.registerOptions(options);\n }\n }\n\n // ---------------------------------------------------------------------------\n // MastraAuthProvider abstract methods\n // ---------------------------------------------------------------------------\n\n /**\n * Authenticate an incoming request by forwarding the sealed session cookie\n * to the shared API's /auth/me endpoint, or a Bearer token to /auth/verify.\n */\n async authenticateToken(token: string, request: any): Promise<StudioUser | null> {\n let user: StudioUser | null = null;\n\n // Try sealed session cookie first (browser flow)\n const cookieHeader = request?.headers?.get('Cookie');\n const sessionCookie = parseCookie(cookieHeader, COOKIE_NAME);\n\n if (sessionCookie) {\n user = await this.verifySessionCookie(sessionCookie);\n }\n\n // Fall back to Bearer token (CLI / API token flow)\n if (!user && token) {\n user = await this.verifyBearerToken(token);\n }\n\n if (!user) return null;\n\n // Org-scoping: if this instance belongs to a specific org, reject users not a member of that org\n // Check memberOrgIds (all orgs user belongs to) rather than organizationId (current org)\n if (this.organizationId && !user.memberOrgIds?.includes(this.organizationId)) {\n return null;\n }\n\n return user;\n }\n\n authorizeUser(user: StudioUser): boolean {\n return !!user?.id;\n }\n\n // ---------------------------------------------------------------------------\n // ISSOProvider\n // ---------------------------------------------------------------------------\n\n getLoginUrl(redirectUri: string, state: string): string {\n // Extract the post-login redirect from state (format: uuid|encodedPostLoginRedirect)\n let postLoginRedirect = '/';\n if (state) {\n const pipeIndex = state.indexOf('|');\n if (pipeIndex !== -1) {\n try {\n postLoginRedirect = decodeURIComponent(state.slice(pipeIndex + 1));\n } catch {\n // ignore decode errors\n }\n }\n }\n\n const params = new URLSearchParams({\n product: 'deploy',\n redirect_uri: redirectUri,\n post_login_redirect: postLoginRedirect,\n // Force re-authentication so AuthKit always shows the account picker\n prompt: 'login',\n ...(this.organizationId ? { organization_id: this.organizationId } : {}),\n });\n\n return `${this.sharedApiUrl}/auth/login?${params.toString()}`;\n }\n\n async handleCallback(code: string, _state: string): Promise<SSOCallbackResult<StudioUser>> {\n // The shared API already consumed the OAuth code and passes the sealed\n // session directly as the `code` parameter in the redirect to this callback.\n // Validate it to get user info.\n const user = await this.verifySessionCookie(code);\n if (!user) {\n throw new Error('Session validation failed');\n }\n\n // Omit `cookies` so the Mastra server fallback path calls\n // createSession() + getSessionHeaders() to build a cookie scoped to\n // the deployed instance's domain.\n return {\n user,\n tokens: {\n accessToken: code,\n },\n };\n }\n\n setCallbackCookieHeader(_cookieHeader: string | null): void {\n // No-op: we don't use PKCE cookies — the shared API handles the full OAuth flow\n }\n\n getLoginCookies(): string[] | undefined {\n // No PKCE cookies needed — shared API manages the OAuth state\n return undefined;\n }\n\n getLoginButtonConfig(): SSOLoginConfig {\n return {\n provider: 'mastra-studio',\n text: 'Sign in with Mastra',\n };\n }\n\n async getLogoutUrl(_redirectUri: string, request?: Request): Promise<string | null> {\n const cookieHeader = request?.headers.get('Cookie');\n const sessionCookie = parseCookie(cookieHeader, COOKIE_NAME);\n\n if (!sessionCookie) return null;\n\n try {\n const res = await fetch(`${this.sharedApiUrl}/auth/logout`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Cookie: `${COOKIE_NAME}=${sessionCookie}`,\n },\n });\n\n if (res.ok) {\n const data = (await res.json()) as { ok: boolean; logoutUrl?: string };\n return data.logoutUrl ?? null;\n }\n } catch {\n // Failed to get logout URL — return null\n }\n\n return null;\n }\n\n // ---------------------------------------------------------------------------\n // ISessionProvider\n // ---------------------------------------------------------------------------\n\n async createSession(userId: string, metadata?: Record<string, unknown>): Promise<Session> {\n const now = new Date();\n return {\n id: (metadata?.accessToken as string) || crypto.randomUUID(),\n userId,\n expiresAt: new Date(now.getTime() + 24 * 60 * 60 * 1000), // 24 hours\n createdAt: now,\n metadata,\n };\n }\n\n async validateSession(sessionId: string): Promise<Session | null> {\n const user = await this.verifySessionCookie(sessionId);\n if (!user) return null;\n\n const now = new Date();\n return {\n id: sessionId,\n userId: user.id,\n expiresAt: new Date(now.getTime() + 24 * 60 * 60 * 1000),\n createdAt: now,\n };\n }\n\n async destroySession(sessionId: string): Promise<void> {\n try {\n await fetch(`${this.sharedApiUrl}/auth/logout`, {\n method: 'POST',\n headers: {\n Cookie: `${COOKIE_NAME}=${sessionId}`,\n },\n });\n } catch {\n // Best effort\n }\n }\n\n async refreshSession(sessionId: string): Promise<Session | null> {\n try {\n // Call the shared API's /auth/refresh endpoint to get a fresh access token\n const res = await fetch(`${this.sharedApiUrl}/auth/refresh`, {\n method: 'GET',\n headers: {\n Cookie: `${COOKIE_NAME}=${sessionId}`,\n },\n });\n\n if (!res.ok) {\n // Refresh failed, fall back to validation (will likely also fail)\n return this.validateSession(sessionId);\n }\n\n // Parse the new sealed session from Set-Cookie header\n const setCookie = res.headers.get('Set-Cookie');\n const newSessionId = setCookie ? parseCookieFromHeader(setCookie, COOKIE_NAME) : null;\n\n if (!newSessionId) {\n // No new cookie returned, fall back to validation with original\n return this.validateSession(sessionId);\n }\n\n // Verify the new session works and return it\n const user = await this.verifySessionCookie(newSessionId);\n if (!user) return null;\n\n const now = new Date();\n return {\n id: newSessionId,\n userId: user.id,\n expiresAt: new Date(now.getTime() + 24 * 60 * 60 * 1000),\n createdAt: now,\n };\n } catch {\n // On error, fall back to validation\n return this.validateSession(sessionId);\n }\n }\n\n getSessionIdFromRequest(request: Request): string | null {\n const cookieHeader = request.headers.get('Cookie');\n return parseCookie(cookieHeader, COOKIE_NAME);\n }\n\n getSessionHeaders(session: Session): Record<string, string> {\n const parts = [`${COOKIE_NAME}=${session.id}`, 'HttpOnly', 'SameSite=Lax', 'Path=/', 'Max-Age=86400'];\n if (this.useProductionCookies && this.cookieDomain) {\n parts.push('Secure');\n parts.push(`Domain=${this.cookieDomain}`);\n }\n return { 'Set-Cookie': parts.join('; ') };\n }\n\n getClearSessionHeaders(): Record<string, string> {\n const parts = [`${COOKIE_NAME}=`, 'HttpOnly', 'SameSite=Lax', 'Path=/', 'Max-Age=0'];\n if (this.useProductionCookies && this.cookieDomain) {\n parts.push('Secure');\n parts.push(`Domain=${this.cookieDomain}`);\n }\n return { 'Set-Cookie': parts.join('; ') };\n }\n\n // ---------------------------------------------------------------------------\n // IUserProvider\n // ---------------------------------------------------------------------------\n\n async getCurrentUser(request: Request): Promise<StudioUser | null> {\n const cookieHeader = request.headers.get('Cookie');\n const sessionCookie = parseCookie(cookieHeader, COOKIE_NAME);\n\n if (sessionCookie) {\n return this.verifySessionCookie(sessionCookie);\n }\n\n // Try bearer token\n const authHeader = request.headers.get('Authorization');\n if (authHeader?.startsWith('Bearer ')) {\n return this.verifyBearerToken(authHeader.slice(7));\n }\n\n return null;\n }\n\n async getUser(_userId: string): Promise<StudioUser | null> {\n // Cannot look up users by ID — only validate sessions\n return null;\n }\n\n // ---------------------------------------------------------------------------\n // Internal helpers\n // ---------------------------------------------------------------------------\n\n /**\n * Forward a sealed session cookie to the shared API's /auth/me endpoint\n * to validate it and get user info.\n */\n private async verifySessionCookie(sessionCookie: string): Promise<StudioUser | null> {\n try {\n const res = await fetch(`${this.sharedApiUrl}/auth/me`, {\n headers: {\n Cookie: `${COOKIE_NAME}=${sessionCookie}`,\n },\n });\n\n if (!res.ok) return null;\n\n const data = (await res.json()) as {\n user: {\n id: string;\n email: string;\n firstName: string;\n lastName: string;\n profilePictureUrl?: string;\n };\n organizationId: string;\n role?: string;\n permissions?: string[];\n memberOrgIds?: string[];\n };\n\n return {\n id: data.user.id,\n email: data.user.email,\n name: [data.user.firstName, data.user.lastName].filter(Boolean).join(' ') || undefined,\n avatarUrl: data.user.profilePictureUrl,\n organizationId: data.organizationId,\n role: data.role,\n permissions: data.permissions,\n memberOrgIds: data.memberOrgIds,\n };\n } catch {\n return null;\n }\n }\n\n /**\n * Forward a Bearer token to the shared API's /auth/verify endpoint\n * to validate it and get user info (used for CLI tokens).\n */\n private async verifyBearerToken(token: string): Promise<StudioUser | null> {\n try {\n const res = await fetch(`${this.sharedApiUrl}/auth/verify`, {\n headers: {\n Authorization: `Bearer ${token}`,\n },\n });\n\n if (!res.ok) return null;\n\n const data = (await res.json()) as {\n user: {\n id: string;\n email: string;\n firstName: string;\n lastName: string;\n };\n organizationId: string;\n role?: string;\n memberOrgIds?: string[];\n };\n\n return {\n id: data.user.id,\n email: data.user.email,\n name: [data.user.firstName, data.user.lastName].filter(Boolean).join(' ') || undefined,\n organizationId: data.organizationId,\n role: data.role,\n memberOrgIds: data.memberOrgIds,\n };\n } catch {\n return null;\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Cookie helpers\n// ---------------------------------------------------------------------------\n\nfunction parseCookie(cookieHeader: string | null | undefined, name: string): string | null {\n if (!cookieHeader) return null;\n const match = cookieHeader.match(new RegExp(`${name}=([^;]+)`));\n return match?.[1] ?? null;\n}\n\n/**\n * Parse a cookie value from a Set-Cookie header.\n * Set-Cookie format: \"name=value; HttpOnly; SameSite=Lax; Path=/; Max-Age=86400\"\n */\nfunction parseCookieFromHeader(setCookieHeader: string, name: string): string | null {\n // Set-Cookie header starts with \"name=value\" followed by optional attributes\n const parts = setCookieHeader.split(';');\n if (parts.length === 0) return null;\n\n const [cookieName, ...valueParts] = parts[0]!.split('=');\n if (cookieName?.trim() !== name) return null;\n\n // Value could contain = characters, so rejoin\n return valueParts.join('=') || null;\n}\n\n// ---------------------------------------------------------------------------\n// MastraRBACStudio — role-based permission provider for Studio auth\n// ---------------------------------------------------------------------------\n\nexport interface MastraRBACStudioOptions {\n /**\n * Mapping from role names to permission arrays.\n *\n * @example\n * ```typescript\n * {\n * admin: ['*'],\n * member: ['agents:read', 'workflows:*'],\n * viewer: ['agents:read', 'workflows:read'],\n * _default: [],\n * }\n * ```\n */\n roleMapping: RoleMapping;\n}\n\n/**\n * RBAC provider for Mastra Studio authentication.\n *\n * Maps user roles (from the shared API's /auth/me endpoint) to Mastra permissions\n * using a configurable role mapping.\n */\nexport class MastraRBACStudio implements IRBACProvider<StudioUser> {\n private options: MastraRBACStudioOptions;\n\n get roleMapping(): RoleMapping {\n return this.options.roleMapping;\n }\n\n constructor(options: MastraRBACStudioOptions) {\n this.options = options;\n }\n\n async getRoles(user: StudioUser): Promise<string[]> {\n return user.role ? [user.role] : [];\n }\n\n async hasRole(user: StudioUser, role: string): Promise<boolean> {\n const roles = await this.getRoles(user);\n return roles.includes(role);\n }\n\n async getPermissions(user: StudioUser): Promise<string[]> {\n const roles = await this.getRoles(user);\n if (roles.length === 0) {\n return this.options.roleMapping['_default'] ?? [];\n }\n return resolvePermissionsFromMapping(roles, this.options.roleMapping);\n }\n\n async hasPermission(user: StudioUser, permission: string): Promise<boolean> {\n const permissions = await this.getPermissions(user);\n return permissions.some(p => matchesPermission(p, permission));\n }\n\n async hasAllPermissions(user: StudioUser, permissions: string[]): Promise<boolean> {\n const userPermissions = await this.getPermissions(user);\n return permissions.every(required => userPermissions.some(p => matchesPermission(p, required)));\n }\n\n async hasAnyPermission(user: StudioUser, permissions: string[]): Promise<boolean> {\n const userPermissions = await this.getPermissions(user);\n return permissions.some(required => userPermissions.some(p => matchesPermission(p, required)));\n }\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { ISSOProvider, ISessionProvider, IUserProvider, Session, SSOCallbackResult, SSOLoginConfig } from '@mastra/core/auth';
|
|
2
|
+
import type { EEUser, IRBACProvider, RoleMapping } from '@mastra/core/auth/ee';
|
|
3
|
+
import { MastraAuthProvider } from '@mastra/core/server';
|
|
4
|
+
import type { MastraAuthProviderOptions } from '@mastra/core/server';
|
|
5
|
+
export interface StudioUser extends EEUser {
|
|
6
|
+
id: string;
|
|
7
|
+
email?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
avatarUrl?: string;
|
|
10
|
+
organizationId?: string;
|
|
11
|
+
role?: string;
|
|
12
|
+
permissions?: string[];
|
|
13
|
+
/** All organization IDs the user is a member of (for cross-org access checks) */
|
|
14
|
+
memberOrgIds?: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface MastraAuthStudioOptions extends MastraAuthProviderOptions<StudioUser> {
|
|
17
|
+
/** Base URL of the Mastra shared API (e.g., https://api.mastra.ai/v1) */
|
|
18
|
+
sharedApiUrl?: string;
|
|
19
|
+
/** Organization ID that owns this deployed instance. Users not in this org are rejected. */
|
|
20
|
+
organizationId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Cookie domain for session cookies (e.g., '.example.com').
|
|
23
|
+
* When set, cookies will include Secure and Domain attributes.
|
|
24
|
+
* Defaults to auto-detecting from sharedApiUrl (uses '.mastra.ai' when sharedApiUrl contains '.mastra.ai').
|
|
25
|
+
* Can also be set via MASTRA_COOKIE_DOMAIN environment variable.
|
|
26
|
+
*/
|
|
27
|
+
cookieDomain?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Auth provider for Mastra Studio deployed instances.
|
|
31
|
+
*
|
|
32
|
+
* Proxies all authentication through the shared API, keeping the
|
|
33
|
+
* WorkOS API key safely in the shared API. Deployed instances only
|
|
34
|
+
* need the shared API URL — no secrets required.
|
|
35
|
+
*
|
|
36
|
+
* The shared API's sealed session cookie (`wos-session`) is set with
|
|
37
|
+
* `Domain=.mastra.ai` in production, so it's included in requests
|
|
38
|
+
* to deployed instances and can be forwarded for validation.
|
|
39
|
+
*/
|
|
40
|
+
export declare class MastraAuthStudio extends MastraAuthProvider<StudioUser> implements ISSOProvider<StudioUser>, ISessionProvider<Session>, IUserProvider<StudioUser> {
|
|
41
|
+
readonly isMastraCloudAuth = true;
|
|
42
|
+
private sharedApiUrl;
|
|
43
|
+
private organizationId;
|
|
44
|
+
private useProductionCookies;
|
|
45
|
+
private cookieDomain;
|
|
46
|
+
constructor(options?: MastraAuthStudioOptions);
|
|
47
|
+
/**
|
|
48
|
+
* Authenticate an incoming request by forwarding the sealed session cookie
|
|
49
|
+
* to the shared API's /auth/me endpoint, or a Bearer token to /auth/verify.
|
|
50
|
+
*/
|
|
51
|
+
authenticateToken(token: string, request: any): Promise<StudioUser | null>;
|
|
52
|
+
authorizeUser(user: StudioUser): boolean;
|
|
53
|
+
getLoginUrl(redirectUri: string, state: string): string;
|
|
54
|
+
handleCallback(code: string, _state: string): Promise<SSOCallbackResult<StudioUser>>;
|
|
55
|
+
setCallbackCookieHeader(_cookieHeader: string | null): void;
|
|
56
|
+
getLoginCookies(): string[] | undefined;
|
|
57
|
+
getLoginButtonConfig(): SSOLoginConfig;
|
|
58
|
+
getLogoutUrl(_redirectUri: string, request?: Request): Promise<string | null>;
|
|
59
|
+
createSession(userId: string, metadata?: Record<string, unknown>): Promise<Session>;
|
|
60
|
+
validateSession(sessionId: string): Promise<Session | null>;
|
|
61
|
+
destroySession(sessionId: string): Promise<void>;
|
|
62
|
+
refreshSession(sessionId: string): Promise<Session | null>;
|
|
63
|
+
getSessionIdFromRequest(request: Request): string | null;
|
|
64
|
+
getSessionHeaders(session: Session): Record<string, string>;
|
|
65
|
+
getClearSessionHeaders(): Record<string, string>;
|
|
66
|
+
getCurrentUser(request: Request): Promise<StudioUser | null>;
|
|
67
|
+
getUser(_userId: string): Promise<StudioUser | null>;
|
|
68
|
+
/**
|
|
69
|
+
* Forward a sealed session cookie to the shared API's /auth/me endpoint
|
|
70
|
+
* to validate it and get user info.
|
|
71
|
+
*/
|
|
72
|
+
private verifySessionCookie;
|
|
73
|
+
/**
|
|
74
|
+
* Forward a Bearer token to the shared API's /auth/verify endpoint
|
|
75
|
+
* to validate it and get user info (used for CLI tokens).
|
|
76
|
+
*/
|
|
77
|
+
private verifyBearerToken;
|
|
78
|
+
}
|
|
79
|
+
export interface MastraRBACStudioOptions {
|
|
80
|
+
/**
|
|
81
|
+
* Mapping from role names to permission arrays.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* {
|
|
86
|
+
* admin: ['*'],
|
|
87
|
+
* member: ['agents:read', 'workflows:*'],
|
|
88
|
+
* viewer: ['agents:read', 'workflows:read'],
|
|
89
|
+
* _default: [],
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
roleMapping: RoleMapping;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* RBAC provider for Mastra Studio authentication.
|
|
97
|
+
*
|
|
98
|
+
* Maps user roles (from the shared API's /auth/me endpoint) to Mastra permissions
|
|
99
|
+
* using a configurable role mapping.
|
|
100
|
+
*/
|
|
101
|
+
export declare class MastraRBACStudio implements IRBACProvider<StudioUser> {
|
|
102
|
+
private options;
|
|
103
|
+
get roleMapping(): RoleMapping;
|
|
104
|
+
constructor(options: MastraRBACStudioOptions);
|
|
105
|
+
getRoles(user: StudioUser): Promise<string[]>;
|
|
106
|
+
hasRole(user: StudioUser, role: string): Promise<boolean>;
|
|
107
|
+
getPermissions(user: StudioUser): Promise<string[]>;
|
|
108
|
+
hasPermission(user: StudioUser, permission: string): Promise<boolean>;
|
|
109
|
+
hasAllPermissions(user: StudioUser, permissions: string[]): Promise<boolean>;
|
|
110
|
+
hasAnyPermission(user: StudioUser, permissions: string[]): Promise<boolean>;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,OAAO,EACP,iBAAiB,EACjB,cAAc,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAE/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAErE,MAAM,WAAW,UAAW,SAAQ,MAAM;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,iFAAiF;IACjF,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,uBAAwB,SAAQ,yBAAyB,CAAC,UAAU,CAAC;IACpF,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4FAA4F;IAC5F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAID;;;;;;;;;;GAUG;AACH,qBAAa,gBACX,SAAQ,kBAAkB,CAAC,UAAU,CACrC,YAAW,YAAY,C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/index.js
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { resolvePermissionsFromMapping, matchesPermission } from '@mastra/core/auth/ee';
|
|
2
|
+
import { MastraAuthProvider } from '@mastra/core/server';
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
var COOKIE_NAME = "wos-session";
|
|
6
|
+
var MastraAuthStudio = class extends MastraAuthProvider {
|
|
7
|
+
isMastraCloudAuth = true;
|
|
8
|
+
sharedApiUrl;
|
|
9
|
+
organizationId;
|
|
10
|
+
useProductionCookies;
|
|
11
|
+
cookieDomain;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super({ name: "mastra-studio", ...options });
|
|
14
|
+
this.sharedApiUrl = options?.sharedApiUrl || process.env.MASTRA_SHARED_API_URL || "http://localhost:3010/v1";
|
|
15
|
+
this.organizationId = options?.organizationId || process.env.MASTRA_ORGANIZATION_ID;
|
|
16
|
+
if (this.sharedApiUrl.endsWith("/")) {
|
|
17
|
+
this.sharedApiUrl = this.sharedApiUrl.slice(0, -1);
|
|
18
|
+
}
|
|
19
|
+
this.cookieDomain = options?.cookieDomain || process.env.MASTRA_COOKIE_DOMAIN;
|
|
20
|
+
let autoDetectMastraAi = false;
|
|
21
|
+
try {
|
|
22
|
+
const hostname = new URL(this.sharedApiUrl).hostname.toLowerCase();
|
|
23
|
+
autoDetectMastraAi = hostname === "mastra.ai" || hostname.endsWith(".mastra.ai");
|
|
24
|
+
} catch {
|
|
25
|
+
autoDetectMastraAi = false;
|
|
26
|
+
}
|
|
27
|
+
this.useProductionCookies = !!this.cookieDomain || autoDetectMastraAi;
|
|
28
|
+
if (!this.cookieDomain && autoDetectMastraAi) {
|
|
29
|
+
this.cookieDomain = ".mastra.ai";
|
|
30
|
+
}
|
|
31
|
+
if (options) {
|
|
32
|
+
this.registerOptions(options);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
// MastraAuthProvider abstract methods
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
/**
|
|
39
|
+
* Authenticate an incoming request by forwarding the sealed session cookie
|
|
40
|
+
* to the shared API's /auth/me endpoint, or a Bearer token to /auth/verify.
|
|
41
|
+
*/
|
|
42
|
+
async authenticateToken(token, request) {
|
|
43
|
+
let user = null;
|
|
44
|
+
const cookieHeader = request?.headers?.get("Cookie");
|
|
45
|
+
const sessionCookie = parseCookie(cookieHeader, COOKIE_NAME);
|
|
46
|
+
if (sessionCookie) {
|
|
47
|
+
user = await this.verifySessionCookie(sessionCookie);
|
|
48
|
+
}
|
|
49
|
+
if (!user && token) {
|
|
50
|
+
user = await this.verifyBearerToken(token);
|
|
51
|
+
}
|
|
52
|
+
if (!user) return null;
|
|
53
|
+
if (this.organizationId && !user.memberOrgIds?.includes(this.organizationId)) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return user;
|
|
57
|
+
}
|
|
58
|
+
authorizeUser(user) {
|
|
59
|
+
return !!user?.id;
|
|
60
|
+
}
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
// ISSOProvider
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
getLoginUrl(redirectUri, state) {
|
|
65
|
+
let postLoginRedirect = "/";
|
|
66
|
+
if (state) {
|
|
67
|
+
const pipeIndex = state.indexOf("|");
|
|
68
|
+
if (pipeIndex !== -1) {
|
|
69
|
+
try {
|
|
70
|
+
postLoginRedirect = decodeURIComponent(state.slice(pipeIndex + 1));
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const params = new URLSearchParams({
|
|
76
|
+
product: "deploy",
|
|
77
|
+
redirect_uri: redirectUri,
|
|
78
|
+
post_login_redirect: postLoginRedirect,
|
|
79
|
+
// Force re-authentication so AuthKit always shows the account picker
|
|
80
|
+
prompt: "login",
|
|
81
|
+
...this.organizationId ? { organization_id: this.organizationId } : {}
|
|
82
|
+
});
|
|
83
|
+
return `${this.sharedApiUrl}/auth/login?${params.toString()}`;
|
|
84
|
+
}
|
|
85
|
+
async handleCallback(code, _state) {
|
|
86
|
+
const user = await this.verifySessionCookie(code);
|
|
87
|
+
if (!user) {
|
|
88
|
+
throw new Error("Session validation failed");
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
user,
|
|
92
|
+
tokens: {
|
|
93
|
+
accessToken: code
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
setCallbackCookieHeader(_cookieHeader) {
|
|
98
|
+
}
|
|
99
|
+
getLoginCookies() {
|
|
100
|
+
return void 0;
|
|
101
|
+
}
|
|
102
|
+
getLoginButtonConfig() {
|
|
103
|
+
return {
|
|
104
|
+
provider: "mastra-studio",
|
|
105
|
+
text: "Sign in with Mastra"
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async getLogoutUrl(_redirectUri, request) {
|
|
109
|
+
const cookieHeader = request?.headers.get("Cookie");
|
|
110
|
+
const sessionCookie = parseCookie(cookieHeader, COOKIE_NAME);
|
|
111
|
+
if (!sessionCookie) return null;
|
|
112
|
+
try {
|
|
113
|
+
const res = await fetch(`${this.sharedApiUrl}/auth/logout`, {
|
|
114
|
+
method: "POST",
|
|
115
|
+
headers: {
|
|
116
|
+
"Content-Type": "application/json",
|
|
117
|
+
Cookie: `${COOKIE_NAME}=${sessionCookie}`
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
if (res.ok) {
|
|
121
|
+
const data = await res.json();
|
|
122
|
+
return data.logoutUrl ?? null;
|
|
123
|
+
}
|
|
124
|
+
} catch {
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
// ISessionProvider
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
async createSession(userId, metadata) {
|
|
132
|
+
const now = /* @__PURE__ */ new Date();
|
|
133
|
+
return {
|
|
134
|
+
id: metadata?.accessToken || crypto.randomUUID(),
|
|
135
|
+
userId,
|
|
136
|
+
expiresAt: new Date(now.getTime() + 24 * 60 * 60 * 1e3),
|
|
137
|
+
// 24 hours
|
|
138
|
+
createdAt: now,
|
|
139
|
+
metadata
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
async validateSession(sessionId) {
|
|
143
|
+
const user = await this.verifySessionCookie(sessionId);
|
|
144
|
+
if (!user) return null;
|
|
145
|
+
const now = /* @__PURE__ */ new Date();
|
|
146
|
+
return {
|
|
147
|
+
id: sessionId,
|
|
148
|
+
userId: user.id,
|
|
149
|
+
expiresAt: new Date(now.getTime() + 24 * 60 * 60 * 1e3),
|
|
150
|
+
createdAt: now
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
async destroySession(sessionId) {
|
|
154
|
+
try {
|
|
155
|
+
await fetch(`${this.sharedApiUrl}/auth/logout`, {
|
|
156
|
+
method: "POST",
|
|
157
|
+
headers: {
|
|
158
|
+
Cookie: `${COOKIE_NAME}=${sessionId}`
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
} catch {
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async refreshSession(sessionId) {
|
|
165
|
+
try {
|
|
166
|
+
const res = await fetch(`${this.sharedApiUrl}/auth/refresh`, {
|
|
167
|
+
method: "GET",
|
|
168
|
+
headers: {
|
|
169
|
+
Cookie: `${COOKIE_NAME}=${sessionId}`
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
if (!res.ok) {
|
|
173
|
+
return this.validateSession(sessionId);
|
|
174
|
+
}
|
|
175
|
+
const setCookie = res.headers.get("Set-Cookie");
|
|
176
|
+
const newSessionId = setCookie ? parseCookieFromHeader(setCookie, COOKIE_NAME) : null;
|
|
177
|
+
if (!newSessionId) {
|
|
178
|
+
return this.validateSession(sessionId);
|
|
179
|
+
}
|
|
180
|
+
const user = await this.verifySessionCookie(newSessionId);
|
|
181
|
+
if (!user) return null;
|
|
182
|
+
const now = /* @__PURE__ */ new Date();
|
|
183
|
+
return {
|
|
184
|
+
id: newSessionId,
|
|
185
|
+
userId: user.id,
|
|
186
|
+
expiresAt: new Date(now.getTime() + 24 * 60 * 60 * 1e3),
|
|
187
|
+
createdAt: now
|
|
188
|
+
};
|
|
189
|
+
} catch {
|
|
190
|
+
return this.validateSession(sessionId);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
getSessionIdFromRequest(request) {
|
|
194
|
+
const cookieHeader = request.headers.get("Cookie");
|
|
195
|
+
return parseCookie(cookieHeader, COOKIE_NAME);
|
|
196
|
+
}
|
|
197
|
+
getSessionHeaders(session) {
|
|
198
|
+
const parts = [`${COOKIE_NAME}=${session.id}`, "HttpOnly", "SameSite=Lax", "Path=/", "Max-Age=86400"];
|
|
199
|
+
if (this.useProductionCookies && this.cookieDomain) {
|
|
200
|
+
parts.push("Secure");
|
|
201
|
+
parts.push(`Domain=${this.cookieDomain}`);
|
|
202
|
+
}
|
|
203
|
+
return { "Set-Cookie": parts.join("; ") };
|
|
204
|
+
}
|
|
205
|
+
getClearSessionHeaders() {
|
|
206
|
+
const parts = [`${COOKIE_NAME}=`, "HttpOnly", "SameSite=Lax", "Path=/", "Max-Age=0"];
|
|
207
|
+
if (this.useProductionCookies && this.cookieDomain) {
|
|
208
|
+
parts.push("Secure");
|
|
209
|
+
parts.push(`Domain=${this.cookieDomain}`);
|
|
210
|
+
}
|
|
211
|
+
return { "Set-Cookie": parts.join("; ") };
|
|
212
|
+
}
|
|
213
|
+
// ---------------------------------------------------------------------------
|
|
214
|
+
// IUserProvider
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
async getCurrentUser(request) {
|
|
217
|
+
const cookieHeader = request.headers.get("Cookie");
|
|
218
|
+
const sessionCookie = parseCookie(cookieHeader, COOKIE_NAME);
|
|
219
|
+
if (sessionCookie) {
|
|
220
|
+
return this.verifySessionCookie(sessionCookie);
|
|
221
|
+
}
|
|
222
|
+
const authHeader = request.headers.get("Authorization");
|
|
223
|
+
if (authHeader?.startsWith("Bearer ")) {
|
|
224
|
+
return this.verifyBearerToken(authHeader.slice(7));
|
|
225
|
+
}
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
async getUser(_userId) {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
// ---------------------------------------------------------------------------
|
|
232
|
+
// Internal helpers
|
|
233
|
+
// ---------------------------------------------------------------------------
|
|
234
|
+
/**
|
|
235
|
+
* Forward a sealed session cookie to the shared API's /auth/me endpoint
|
|
236
|
+
* to validate it and get user info.
|
|
237
|
+
*/
|
|
238
|
+
async verifySessionCookie(sessionCookie) {
|
|
239
|
+
try {
|
|
240
|
+
const res = await fetch(`${this.sharedApiUrl}/auth/me`, {
|
|
241
|
+
headers: {
|
|
242
|
+
Cookie: `${COOKIE_NAME}=${sessionCookie}`
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
if (!res.ok) return null;
|
|
246
|
+
const data = await res.json();
|
|
247
|
+
return {
|
|
248
|
+
id: data.user.id,
|
|
249
|
+
email: data.user.email,
|
|
250
|
+
name: [data.user.firstName, data.user.lastName].filter(Boolean).join(" ") || void 0,
|
|
251
|
+
avatarUrl: data.user.profilePictureUrl,
|
|
252
|
+
organizationId: data.organizationId,
|
|
253
|
+
role: data.role,
|
|
254
|
+
permissions: data.permissions,
|
|
255
|
+
memberOrgIds: data.memberOrgIds
|
|
256
|
+
};
|
|
257
|
+
} catch {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Forward a Bearer token to the shared API's /auth/verify endpoint
|
|
263
|
+
* to validate it and get user info (used for CLI tokens).
|
|
264
|
+
*/
|
|
265
|
+
async verifyBearerToken(token) {
|
|
266
|
+
try {
|
|
267
|
+
const res = await fetch(`${this.sharedApiUrl}/auth/verify`, {
|
|
268
|
+
headers: {
|
|
269
|
+
Authorization: `Bearer ${token}`
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
if (!res.ok) return null;
|
|
273
|
+
const data = await res.json();
|
|
274
|
+
return {
|
|
275
|
+
id: data.user.id,
|
|
276
|
+
email: data.user.email,
|
|
277
|
+
name: [data.user.firstName, data.user.lastName].filter(Boolean).join(" ") || void 0,
|
|
278
|
+
organizationId: data.organizationId,
|
|
279
|
+
role: data.role,
|
|
280
|
+
memberOrgIds: data.memberOrgIds
|
|
281
|
+
};
|
|
282
|
+
} catch {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
function parseCookie(cookieHeader, name) {
|
|
288
|
+
if (!cookieHeader) return null;
|
|
289
|
+
const match = cookieHeader.match(new RegExp(`${name}=([^;]+)`));
|
|
290
|
+
return match?.[1] ?? null;
|
|
291
|
+
}
|
|
292
|
+
function parseCookieFromHeader(setCookieHeader, name) {
|
|
293
|
+
const parts = setCookieHeader.split(";");
|
|
294
|
+
if (parts.length === 0) return null;
|
|
295
|
+
const [cookieName, ...valueParts] = parts[0].split("=");
|
|
296
|
+
if (cookieName?.trim() !== name) return null;
|
|
297
|
+
return valueParts.join("=") || null;
|
|
298
|
+
}
|
|
299
|
+
var MastraRBACStudio = class {
|
|
300
|
+
options;
|
|
301
|
+
get roleMapping() {
|
|
302
|
+
return this.options.roleMapping;
|
|
303
|
+
}
|
|
304
|
+
constructor(options) {
|
|
305
|
+
this.options = options;
|
|
306
|
+
}
|
|
307
|
+
async getRoles(user) {
|
|
308
|
+
return user.role ? [user.role] : [];
|
|
309
|
+
}
|
|
310
|
+
async hasRole(user, role) {
|
|
311
|
+
const roles = await this.getRoles(user);
|
|
312
|
+
return roles.includes(role);
|
|
313
|
+
}
|
|
314
|
+
async getPermissions(user) {
|
|
315
|
+
const roles = await this.getRoles(user);
|
|
316
|
+
if (roles.length === 0) {
|
|
317
|
+
return this.options.roleMapping["_default"] ?? [];
|
|
318
|
+
}
|
|
319
|
+
return resolvePermissionsFromMapping(roles, this.options.roleMapping);
|
|
320
|
+
}
|
|
321
|
+
async hasPermission(user, permission) {
|
|
322
|
+
const permissions = await this.getPermissions(user);
|
|
323
|
+
return permissions.some((p) => matchesPermission(p, permission));
|
|
324
|
+
}
|
|
325
|
+
async hasAllPermissions(user, permissions) {
|
|
326
|
+
const userPermissions = await this.getPermissions(user);
|
|
327
|
+
return permissions.every((required) => userPermissions.some((p) => matchesPermission(p, required)));
|
|
328
|
+
}
|
|
329
|
+
async hasAnyPermission(user, permissions) {
|
|
330
|
+
const userPermissions = await this.getPermissions(user);
|
|
331
|
+
return permissions.some((required) => userPermissions.some((p) => matchesPermission(p, required)));
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
export { MastraAuthStudio, MastraRBACStudio };
|
|
336
|
+
//# sourceMappingURL=index.js.map
|
|
337
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAuCA,IAAM,WAAA,GAAc,aAAA;AAab,IAAM,gBAAA,GAAN,cACG,kBAAA,CAEV;AAAA,EACW,iBAAA,GAAoB,IAAA;AAAA,EAErB,YAAA;AAAA,EACA,cAAA;AAAA,EACA,oBAAA;AAAA,EACA,YAAA;AAAA,EAER,YAAY,OAAA,EAAmC;AAC7C,IAAA,KAAA,CAAM,EAAE,IAAA,EAAM,eAAA,EAAiB,GAAG,SAAS,CAAA;AAC3C,IAAA,IAAA,CAAK,YAAA,GAAe,OAAA,EAAS,YAAA,IAAgB,OAAA,CAAQ,IAAI,qBAAA,IAAyB,0BAAA;AAClF,IAAA,IAAA,CAAK,cAAA,GAAiB,OAAA,EAAS,cAAA,IAAkB,OAAA,CAAQ,GAAA,CAAI,sBAAA;AAG7D,IAAA,IAAI,IAAA,CAAK,YAAA,CAAa,QAAA,CAAS,GAAG,CAAA,EAAG;AACnC,MAAA,IAAA,CAAK,YAAA,GAAe,IAAA,CAAK,YAAA,CAAa,KAA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,OAAA,CAAQ,WAAA,CAAY,UAAU,KAAK,EAAC;AAAA,IAClD;AACA,IAAA,OAAO,6BAAA,CAA8B,KAAA,EAAO,IAAA,CAAK,OAAA,CAAQ,WAAW,CAAA;AAAA,EACtE;AAAA,EAEA,MAAM,aAAA,CAAc,IAAA,EAAkB,UAAA,EAAsC;AAC1E,IAAA,MAAM,WAAA,GAAc,MAAM,IAAA,CAAK,cAAA,CAAe,IAAI,CAAA;AAClD,IAAA,OAAO,YAAY,IAAA,CAAK,CAAA,CAAA,KAAK,iBAAA,CAAkB,CAAA,EAAG,UAAU,CAAC,CAAA;AAAA,EAC/D;AAAA,EAEA,MAAM,iBAAA,CAAkB,IAAA,EAAkB,WAAA,EAAyC;AACjF,IAAA,MAAM,eAAA,GAAkB,MAAM,IAAA,CAAK,cAAA,CAAe,IAAI,CAAA;AACtD,IAAA,OAAO,WAAA,CAAY,KAAA,CAAM,CAAA,QAAA,KAAY,eAAA,CAAgB,IAAA,CAAK,OAAK,iBAAA,CAAkB,CAAA,EAAG,QAAQ,CAAC,CAAC,CAAA;AAAA,EAChG;AAAA,EAEA,MAAM,gBAAA,CAAiB,IAAA,EAAkB,WAAA,EAAyC;AAChF,IAAA,MAAM,eAAA,GAAkB,MAAM,IAAA,CAAK,cAAA,CAAe,IAAI,CAAA;AACtD,IAAA,OAAO,WAAA,CAAY,IAAA,CAAK,CAAA,QAAA,KAAY,eAAA,CAAgB,IAAA,CAAK,OAAK,iBAAA,CAAkB,CAAA,EAAG,QAAQ,CAAC,CAAC,CAAA;AAAA,EAC/F;AACF","file":"index.js","sourcesContent":["import type {\n ISSOProvider,\n ISessionProvider,\n IUserProvider,\n Session,\n SSOCallbackResult,\n SSOLoginConfig,\n} from '@mastra/core/auth';\nimport type { EEUser, IRBACProvider, RoleMapping } from '@mastra/core/auth/ee';\nimport { resolvePermissionsFromMapping, matchesPermission } from '@mastra/core/auth/ee';\nimport { MastraAuthProvider } from '@mastra/core/server';\nimport type { MastraAuthProviderOptions } from '@mastra/core/server';\n\nexport interface StudioUser extends EEUser {\n id: string;\n email?: string;\n name?: string;\n avatarUrl?: string;\n organizationId?: string;\n role?: string;\n permissions?: string[];\n /** All organization IDs the user is a member of (for cross-org access checks) */\n memberOrgIds?: string[];\n}\n\nexport interface MastraAuthStudioOptions extends MastraAuthProviderOptions<StudioUser> {\n /** Base URL of the Mastra shared API (e.g., https://api.mastra.ai/v1) */\n sharedApiUrl?: string;\n /** Organization ID that owns this deployed instance. Users not in this org are rejected. */\n organizationId?: string;\n /**\n * Cookie domain for session cookies (e.g., '.example.com').\n * When set, cookies will include Secure and Domain attributes.\n * Defaults to auto-detecting from sharedApiUrl (uses '.mastra.ai' when sharedApiUrl contains '.mastra.ai').\n * Can also be set via MASTRA_COOKIE_DOMAIN environment variable.\n */\n cookieDomain?: string;\n}\n\nconst COOKIE_NAME = 'wos-session';\n\n/**\n * Auth provider for Mastra Studio deployed instances.\n *\n * Proxies all authentication through the shared API, keeping the\n * WorkOS API key safely in the shared API. Deployed instances only\n * need the shared API URL — no secrets required.\n *\n * The shared API's sealed session cookie (`wos-session`) is set with\n * `Domain=.mastra.ai` in production, so it's included in requests\n * to deployed instances and can be forwarded for validation.\n */\nexport class MastraAuthStudio\n extends MastraAuthProvider<StudioUser>\n implements ISSOProvider<StudioUser>, ISessionProvider<Session>, IUserProvider<StudioUser>\n{\n readonly isMastraCloudAuth = true;\n\n private sharedApiUrl: string;\n private organizationId: string | undefined;\n private useProductionCookies: boolean;\n private cookieDomain: string | undefined;\n\n constructor(options?: MastraAuthStudioOptions) {\n super({ name: 'mastra-studio', ...options });\n this.sharedApiUrl = options?.sharedApiUrl || process.env.MASTRA_SHARED_API_URL || 'http://localhost:3010/v1';\n this.organizationId = options?.organizationId || process.env.MASTRA_ORGANIZATION_ID;\n\n // Strip trailing slash\n if (this.sharedApiUrl.endsWith('/')) {\n this.sharedApiUrl = this.sharedApiUrl.slice(0, -1);\n }\n\n // Cookie domain can be explicitly configured, read from env, or auto-detected from sharedApiUrl\n this.cookieDomain = options?.cookieDomain || process.env.MASTRA_COOKIE_DOMAIN;\n\n // Use production cookie settings (Secure + Domain) when:\n // 1. An explicit cookieDomain is configured, OR\n // 2. The shared API is on .mastra.ai (auto-detect default domain)\n // Use hostname-based detection to avoid false positives (e.g., api.mastra.ai.evil.com)\n let autoDetectMastraAi = false;\n try {\n const hostname = new URL(this.sharedApiUrl).hostname.toLowerCase();\n autoDetectMastraAi = hostname === 'mastra.ai' || hostname.endsWith('.mastra.ai');\n } catch {\n autoDetectMastraAi = false;\n }\n this.useProductionCookies = !!this.cookieDomain || autoDetectMastraAi;\n\n // If no explicit domain but we're on .mastra.ai, use the default domain\n if (!this.cookieDomain && autoDetectMastraAi) {\n this.cookieDomain = '.mastra.ai';\n }\n\n if (options) {\n this.registerOptions(options);\n }\n }\n\n // ---------------------------------------------------------------------------\n // MastraAuthProvider abstract methods\n // ---------------------------------------------------------------------------\n\n /**\n * Authenticate an incoming request by forwarding the sealed session cookie\n * to the shared API's /auth/me endpoint, or a Bearer token to /auth/verify.\n */\n async authenticateToken(token: string, request: any): Promise<StudioUser | null> {\n let user: StudioUser | null = null;\n\n // Try sealed session cookie first (browser flow)\n const cookieHeader = request?.headers?.get('Cookie');\n const sessionCookie = parseCookie(cookieHeader, COOKIE_NAME);\n\n if (sessionCookie) {\n user = await this.verifySessionCookie(sessionCookie);\n }\n\n // Fall back to Bearer token (CLI / API token flow)\n if (!user && token) {\n user = await this.verifyBearerToken(token);\n }\n\n if (!user) return null;\n\n // Org-scoping: if this instance belongs to a specific org, reject users not a member of that org\n // Check memberOrgIds (all orgs user belongs to) rather than organizationId (current org)\n if (this.organizationId && !user.memberOrgIds?.includes(this.organizationId)) {\n return null;\n }\n\n return user;\n }\n\n authorizeUser(user: StudioUser): boolean {\n return !!user?.id;\n }\n\n // ---------------------------------------------------------------------------\n // ISSOProvider\n // ---------------------------------------------------------------------------\n\n getLoginUrl(redirectUri: string, state: string): string {\n // Extract the post-login redirect from state (format: uuid|encodedPostLoginRedirect)\n let postLoginRedirect = '/';\n if (state) {\n const pipeIndex = state.indexOf('|');\n if (pipeIndex !== -1) {\n try {\n postLoginRedirect = decodeURIComponent(state.slice(pipeIndex + 1));\n } catch {\n // ignore decode errors\n }\n }\n }\n\n const params = new URLSearchParams({\n product: 'deploy',\n redirect_uri: redirectUri,\n post_login_redirect: postLoginRedirect,\n // Force re-authentication so AuthKit always shows the account picker\n prompt: 'login',\n ...(this.organizationId ? { organization_id: this.organizationId } : {}),\n });\n\n return `${this.sharedApiUrl}/auth/login?${params.toString()}`;\n }\n\n async handleCallback(code: string, _state: string): Promise<SSOCallbackResult<StudioUser>> {\n // The shared API already consumed the OAuth code and passes the sealed\n // session directly as the `code` parameter in the redirect to this callback.\n // Validate it to get user info.\n const user = await this.verifySessionCookie(code);\n if (!user) {\n throw new Error('Session validation failed');\n }\n\n // Omit `cookies` so the Mastra server fallback path calls\n // createSession() + getSessionHeaders() to build a cookie scoped to\n // the deployed instance's domain.\n return {\n user,\n tokens: {\n accessToken: code,\n },\n };\n }\n\n setCallbackCookieHeader(_cookieHeader: string | null): void {\n // No-op: we don't use PKCE cookies — the shared API handles the full OAuth flow\n }\n\n getLoginCookies(): string[] | undefined {\n // No PKCE cookies needed — shared API manages the OAuth state\n return undefined;\n }\n\n getLoginButtonConfig(): SSOLoginConfig {\n return {\n provider: 'mastra-studio',\n text: 'Sign in with Mastra',\n };\n }\n\n async getLogoutUrl(_redirectUri: string, request?: Request): Promise<string | null> {\n const cookieHeader = request?.headers.get('Cookie');\n const sessionCookie = parseCookie(cookieHeader, COOKIE_NAME);\n\n if (!sessionCookie) return null;\n\n try {\n const res = await fetch(`${this.sharedApiUrl}/auth/logout`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Cookie: `${COOKIE_NAME}=${sessionCookie}`,\n },\n });\n\n if (res.ok) {\n const data = (await res.json()) as { ok: boolean; logoutUrl?: string };\n return data.logoutUrl ?? null;\n }\n } catch {\n // Failed to get logout URL — return null\n }\n\n return null;\n }\n\n // ---------------------------------------------------------------------------\n // ISessionProvider\n // ---------------------------------------------------------------------------\n\n async createSession(userId: string, metadata?: Record<string, unknown>): Promise<Session> {\n const now = new Date();\n return {\n id: (metadata?.accessToken as string) || crypto.randomUUID(),\n userId,\n expiresAt: new Date(now.getTime() + 24 * 60 * 60 * 1000), // 24 hours\n createdAt: now,\n metadata,\n };\n }\n\n async validateSession(sessionId: string): Promise<Session | null> {\n const user = await this.verifySessionCookie(sessionId);\n if (!user) return null;\n\n const now = new Date();\n return {\n id: sessionId,\n userId: user.id,\n expiresAt: new Date(now.getTime() + 24 * 60 * 60 * 1000),\n createdAt: now,\n };\n }\n\n async destroySession(sessionId: string): Promise<void> {\n try {\n await fetch(`${this.sharedApiUrl}/auth/logout`, {\n method: 'POST',\n headers: {\n Cookie: `${COOKIE_NAME}=${sessionId}`,\n },\n });\n } catch {\n // Best effort\n }\n }\n\n async refreshSession(sessionId: string): Promise<Session | null> {\n try {\n // Call the shared API's /auth/refresh endpoint to get a fresh access token\n const res = await fetch(`${this.sharedApiUrl}/auth/refresh`, {\n method: 'GET',\n headers: {\n Cookie: `${COOKIE_NAME}=${sessionId}`,\n },\n });\n\n if (!res.ok) {\n // Refresh failed, fall back to validation (will likely also fail)\n return this.validateSession(sessionId);\n }\n\n // Parse the new sealed session from Set-Cookie header\n const setCookie = res.headers.get('Set-Cookie');\n const newSessionId = setCookie ? parseCookieFromHeader(setCookie, COOKIE_NAME) : null;\n\n if (!newSessionId) {\n // No new cookie returned, fall back to validation with original\n return this.validateSession(sessionId);\n }\n\n // Verify the new session works and return it\n const user = await this.verifySessionCookie(newSessionId);\n if (!user) return null;\n\n const now = new Date();\n return {\n id: newSessionId,\n userId: user.id,\n expiresAt: new Date(now.getTime() + 24 * 60 * 60 * 1000),\n createdAt: now,\n };\n } catch {\n // On error, fall back to validation\n return this.validateSession(sessionId);\n }\n }\n\n getSessionIdFromRequest(request: Request): string | null {\n const cookieHeader = request.headers.get('Cookie');\n return parseCookie(cookieHeader, COOKIE_NAME);\n }\n\n getSessionHeaders(session: Session): Record<string, string> {\n const parts = [`${COOKIE_NAME}=${session.id}`, 'HttpOnly', 'SameSite=Lax', 'Path=/', 'Max-Age=86400'];\n if (this.useProductionCookies && this.cookieDomain) {\n parts.push('Secure');\n parts.push(`Domain=${this.cookieDomain}`);\n }\n return { 'Set-Cookie': parts.join('; ') };\n }\n\n getClearSessionHeaders(): Record<string, string> {\n const parts = [`${COOKIE_NAME}=`, 'HttpOnly', 'SameSite=Lax', 'Path=/', 'Max-Age=0'];\n if (this.useProductionCookies && this.cookieDomain) {\n parts.push('Secure');\n parts.push(`Domain=${this.cookieDomain}`);\n }\n return { 'Set-Cookie': parts.join('; ') };\n }\n\n // ---------------------------------------------------------------------------\n // IUserProvider\n // ---------------------------------------------------------------------------\n\n async getCurrentUser(request: Request): Promise<StudioUser | null> {\n const cookieHeader = request.headers.get('Cookie');\n const sessionCookie = parseCookie(cookieHeader, COOKIE_NAME);\n\n if (sessionCookie) {\n return this.verifySessionCookie(sessionCookie);\n }\n\n // Try bearer token\n const authHeader = request.headers.get('Authorization');\n if (authHeader?.startsWith('Bearer ')) {\n return this.verifyBearerToken(authHeader.slice(7));\n }\n\n return null;\n }\n\n async getUser(_userId: string): Promise<StudioUser | null> {\n // Cannot look up users by ID — only validate sessions\n return null;\n }\n\n // ---------------------------------------------------------------------------\n // Internal helpers\n // ---------------------------------------------------------------------------\n\n /**\n * Forward a sealed session cookie to the shared API's /auth/me endpoint\n * to validate it and get user info.\n */\n private async verifySessionCookie(sessionCookie: string): Promise<StudioUser | null> {\n try {\n const res = await fetch(`${this.sharedApiUrl}/auth/me`, {\n headers: {\n Cookie: `${COOKIE_NAME}=${sessionCookie}`,\n },\n });\n\n if (!res.ok) return null;\n\n const data = (await res.json()) as {\n user: {\n id: string;\n email: string;\n firstName: string;\n lastName: string;\n profilePictureUrl?: string;\n };\n organizationId: string;\n role?: string;\n permissions?: string[];\n memberOrgIds?: string[];\n };\n\n return {\n id: data.user.id,\n email: data.user.email,\n name: [data.user.firstName, data.user.lastName].filter(Boolean).join(' ') || undefined,\n avatarUrl: data.user.profilePictureUrl,\n organizationId: data.organizationId,\n role: data.role,\n permissions: data.permissions,\n memberOrgIds: data.memberOrgIds,\n };\n } catch {\n return null;\n }\n }\n\n /**\n * Forward a Bearer token to the shared API's /auth/verify endpoint\n * to validate it and get user info (used for CLI tokens).\n */\n private async verifyBearerToken(token: string): Promise<StudioUser | null> {\n try {\n const res = await fetch(`${this.sharedApiUrl}/auth/verify`, {\n headers: {\n Authorization: `Bearer ${token}`,\n },\n });\n\n if (!res.ok) return null;\n\n const data = (await res.json()) as {\n user: {\n id: string;\n email: string;\n firstName: string;\n lastName: string;\n };\n organizationId: string;\n role?: string;\n memberOrgIds?: string[];\n };\n\n return {\n id: data.user.id,\n email: data.user.email,\n name: [data.user.firstName, data.user.lastName].filter(Boolean).join(' ') || undefined,\n organizationId: data.organizationId,\n role: data.role,\n memberOrgIds: data.memberOrgIds,\n };\n } catch {\n return null;\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Cookie helpers\n// ---------------------------------------------------------------------------\n\nfunction parseCookie(cookieHeader: string | null | undefined, name: string): string | null {\n if (!cookieHeader) return null;\n const match = cookieHeader.match(new RegExp(`${name}=([^;]+)`));\n return match?.[1] ?? null;\n}\n\n/**\n * Parse a cookie value from a Set-Cookie header.\n * Set-Cookie format: \"name=value; HttpOnly; SameSite=Lax; Path=/; Max-Age=86400\"\n */\nfunction parseCookieFromHeader(setCookieHeader: string, name: string): string | null {\n // Set-Cookie header starts with \"name=value\" followed by optional attributes\n const parts = setCookieHeader.split(';');\n if (parts.length === 0) return null;\n\n const [cookieName, ...valueParts] = parts[0]!.split('=');\n if (cookieName?.trim() !== name) return null;\n\n // Value could contain = characters, so rejoin\n return valueParts.join('=') || null;\n}\n\n// ---------------------------------------------------------------------------\n// MastraRBACStudio — role-based permission provider for Studio auth\n// ---------------------------------------------------------------------------\n\nexport interface MastraRBACStudioOptions {\n /**\n * Mapping from role names to permission arrays.\n *\n * @example\n * ```typescript\n * {\n * admin: ['*'],\n * member: ['agents:read', 'workflows:*'],\n * viewer: ['agents:read', 'workflows:read'],\n * _default: [],\n * }\n * ```\n */\n roleMapping: RoleMapping;\n}\n\n/**\n * RBAC provider for Mastra Studio authentication.\n *\n * Maps user roles (from the shared API's /auth/me endpoint) to Mastra permissions\n * using a configurable role mapping.\n */\nexport class MastraRBACStudio implements IRBACProvider<StudioUser> {\n private options: MastraRBACStudioOptions;\n\n get roleMapping(): RoleMapping {\n return this.options.roleMapping;\n }\n\n constructor(options: MastraRBACStudioOptions) {\n this.options = options;\n }\n\n async getRoles(user: StudioUser): Promise<string[]> {\n return user.role ? [user.role] : [];\n }\n\n async hasRole(user: StudioUser, role: string): Promise<boolean> {\n const roles = await this.getRoles(user);\n return roles.includes(role);\n }\n\n async getPermissions(user: StudioUser): Promise<string[]> {\n const roles = await this.getRoles(user);\n if (roles.length === 0) {\n return this.options.roleMapping['_default'] ?? [];\n }\n return resolvePermissionsFromMapping(roles, this.options.roleMapping);\n }\n\n async hasPermission(user: StudioUser, permission: string): Promise<boolean> {\n const permissions = await this.getPermissions(user);\n return permissions.some(p => matchesPermission(p, permission));\n }\n\n async hasAllPermissions(user: StudioUser, permissions: string[]): Promise<boolean> {\n const userPermissions = await this.getPermissions(user);\n return permissions.every(required => userPermissions.some(p => matchesPermission(p, required)));\n }\n\n async hasAnyPermission(user: StudioUser, permissions: string[]): Promise<boolean> {\n const userPermissions = await this.getPermissions(user);\n return permissions.some(required => userPermissions.some(p => matchesPermission(p, required)));\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mastra/auth-studio",
|
|
3
|
+
"version": "0.0.0-a2a-vnext-20260424123427",
|
|
4
|
+
"description": "Mastra Studio Auth integration — proxies authentication through Mastra shared API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "22.19.15",
|
|
24
|
+
"@vitest/coverage-v8": "4.1.5",
|
|
25
|
+
"@vitest/ui": "4.1.5",
|
|
26
|
+
"eslint": "^10.2.1",
|
|
27
|
+
"tsup": "^8.5.1",
|
|
28
|
+
"typescript": "^5.9.3",
|
|
29
|
+
"vitest": "4.1.5",
|
|
30
|
+
"@internal/types-builder": "0.0.0-a2a-vnext-20260424123427",
|
|
31
|
+
"@mastra/core": "0.0.0-a2a-vnext-20260424123427",
|
|
32
|
+
"@internal/lint": "0.0.0-a2a-vnext-20260424123427"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@mastra/core": "0.0.0-a2a-vnext-20260424123427"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"CHANGELOG.md"
|
|
40
|
+
],
|
|
41
|
+
"homepage": "https://mastra.ai",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/mastra-ai/mastra.git",
|
|
45
|
+
"directory": "auth/studio"
|
|
46
|
+
},
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=22.13.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup --silent --config tsup.config.ts",
|
|
55
|
+
"build:watch": "tsup --watch --silent --config tsup.config.ts",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"lint": "eslint ."
|
|
58
|
+
}
|
|
59
|
+
}
|