@mastra/auth-workos 1.6.5-alpha.0 → 1.6.5-alpha.1
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/README.md +13 -116
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,140 +1,37 @@
|
|
|
1
1
|
# @mastra/auth-workos
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- 🔐 WorkOS authentication integration
|
|
8
|
-
- 👥 User management and organization membership support
|
|
9
|
-
- 🔑 JWT token verification using WorkOS JWKS
|
|
10
|
-
- 👮 Role-based authorization with `MastraRBACWorkos`
|
|
11
|
-
- 🔒 Fine-Grained Authorization with `MastraFGAWorkos`
|
|
3
|
+
`@mastra/auth-workos` connects WorkOS authentication, organization memberships, and fine-grained authorization to Mastra. Use it for enterprise SSO deployments where WorkOS identities and roles should control access to Mastra resources.
|
|
12
4
|
|
|
13
5
|
## Installation
|
|
14
6
|
|
|
15
7
|
```bash
|
|
16
8
|
npm install @mastra/auth-workos
|
|
17
|
-
# or
|
|
18
|
-
yarn add @mastra/auth-workos
|
|
19
|
-
# or
|
|
20
|
-
pnpm add @mastra/auth-workos
|
|
21
9
|
```
|
|
22
10
|
|
|
23
11
|
## Usage
|
|
24
12
|
|
|
13
|
+
Set `WORKOS_API_KEY`, `WORKOS_CLIENT_ID`, `WORKOS_REDIRECT_URI`, and the cookie password required by your deployment.
|
|
14
|
+
|
|
25
15
|
```typescript
|
|
16
|
+
import { MastraAuthWorkos } from '@mastra/auth-workos';
|
|
26
17
|
import { Mastra } from '@mastra/core/mastra';
|
|
27
|
-
import { MastraFGAPermissions } from '@mastra/core/auth/ee';
|
|
28
|
-
import { MastraAuthWorkos, MastraFGAWorkos } from '@mastra/auth-workos';
|
|
29
18
|
|
|
30
|
-
|
|
31
|
-
const auth = new MastraAuthWorkos();
|
|
32
|
-
|
|
33
|
-
// Or initialize with explicit configuration
|
|
34
|
-
const auth = new MastraAuthWorkos({
|
|
35
|
-
apiKey: 'your_workos_api_key',
|
|
36
|
-
clientId: 'your_workos_client_id',
|
|
37
|
-
redirectUri: 'https://your-app.com/auth/callback',
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Enable auth in Mastra
|
|
41
|
-
const mastra = new Mastra({
|
|
42
|
-
...
|
|
19
|
+
export const mastra = new Mastra({
|
|
43
20
|
server: {
|
|
44
|
-
auth,
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
`MastraAuthWorkos` authorizes any authenticated WorkOS user by default.
|
|
50
|
-
|
|
51
|
-
If you also use `MastraFGAWorkos`, set `fetchMemberships: true` so Mastra loads organization memberships during authentication:
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
const auth = new MastraAuthWorkos({
|
|
55
|
-
apiKey: 'your_workos_api_key',
|
|
56
|
-
clientId: 'your_workos_client_id',
|
|
57
|
-
redirectUri: 'https://your-app.com/auth/callback',
|
|
58
|
-
fetchMemberships: true,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const fga = new MastraFGAWorkos({
|
|
62
|
-
apiKey: 'your_workos_api_key',
|
|
63
|
-
clientId: 'your_workos_client_id',
|
|
64
|
-
resourceMapping: {
|
|
65
|
-
thread: {
|
|
66
|
-
fgaResourceType: 'workspace-thread',
|
|
67
|
-
deriveId: ({ resourceId, user }) => resourceId ?? user.id,
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
permissionMapping: {
|
|
71
|
-
[MastraFGAPermissions.MEMORY_READ]: 'read',
|
|
72
|
-
[MastraFGAPermissions.MEMORY_WRITE]: 'update',
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
`thread` is the canonical Mastra resource key for memory authorization. `MastraFGAWorkos` also accepts the legacy alias `memory` for backward compatibility.
|
|
78
|
-
|
|
79
|
-
## Configuration
|
|
80
|
-
|
|
81
|
-
The package requires the following configuration:
|
|
82
|
-
|
|
83
|
-
### Environment Variables
|
|
84
|
-
|
|
85
|
-
- `WORKOS_API_KEY`: Your WorkOS API key
|
|
86
|
-
- `WORKOS_CLIENT_ID`: Your WorkOS client ID
|
|
87
|
-
- `WORKOS_REDIRECT_URI`: Your WorkOS redirect URI when you use the built-in AuthKit session flow
|
|
88
|
-
|
|
89
|
-
### Options
|
|
90
|
-
|
|
91
|
-
You can also provide these values directly when initializing the provider:
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
interface MastraAuthWorkosOptions {
|
|
95
|
-
apiKey?: string;
|
|
96
|
-
clientId?: string;
|
|
97
|
-
redirectUri?: string;
|
|
98
|
-
fetchMemberships?: boolean;
|
|
99
|
-
trustJwtClaims?: boolean;
|
|
100
|
-
jwtClaims?: {
|
|
101
|
-
userId?: string;
|
|
102
|
-
workosId?: string;
|
|
103
|
-
email?: string;
|
|
104
|
-
name?: string;
|
|
105
|
-
organizationId?: string;
|
|
106
|
-
organizationMembershipId?: string;
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### Service tokens and custom JWT claims
|
|
112
|
-
|
|
113
|
-
If your WorkOS JWT template includes custom claims for service principals or pre-resolved FGA context, you can map them directly into the authenticated `WorkOSUser`:
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
|
-
const auth = new MastraAuthWorkos({
|
|
117
|
-
apiKey: 'your_workos_api_key',
|
|
118
|
-
clientId: 'your_workos_client_id',
|
|
119
|
-
redirectUri: 'https://your-app.com/auth/callback',
|
|
120
|
-
trustJwtClaims: true,
|
|
121
|
-
jwtClaims: {
|
|
122
|
-
organizationMembershipId: 'urn:mastra:organization_membership_id',
|
|
123
|
-
organizationId: 'org_id',
|
|
21
|
+
auth: new MastraAuthWorkos(),
|
|
124
22
|
},
|
|
125
23
|
});
|
|
126
24
|
```
|
|
127
25
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
For in-process cron jobs, scheduled workflows, and other trusted background work that has no JWT or human membership, pass the core FGA `actor` option on the specific agent, workflow, or tool invocation instead of adding a fake membership to the user. The request context must include an `organizationId`; Mastra denies trusted actor FGA checks without tenant scope.
|
|
26
|
+
## Documentation
|
|
131
27
|
|
|
132
|
-
|
|
28
|
+
- [WorkOS integration guide](https://mastra.ai/integrations/auth/workos)
|
|
29
|
+
- [WorkOS provider reference](https://mastra.ai/reference/auth/workos)
|
|
133
30
|
|
|
134
|
-
|
|
31
|
+
## Changelog
|
|
135
32
|
|
|
136
|
-
|
|
33
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/auth/workos/CHANGELOG.md) for version history and release notes.
|
|
137
34
|
|
|
138
|
-
|
|
35
|
+
## Support
|
|
139
36
|
|
|
140
|
-
|
|
37
|
+
We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/auth-workos",
|
|
3
|
-
"version": "1.6.5-alpha.
|
|
3
|
+
"version": "1.6.5-alpha.1",
|
|
4
4
|
"description": "Mastra WorkOS Auth integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@workos-inc/node": "8.13.0",
|
|
24
24
|
"@workos/authkit-session": "^0.7.1",
|
|
25
25
|
"lru-cache": "^11.2.7",
|
|
26
|
-
"@mastra/auth": "1.1.3-alpha.
|
|
26
|
+
"@mastra/auth": "1.1.3-alpha.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"hono": "^4.0.0"
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"tsdown": "0.22.9",
|
|
37
37
|
"typescript": "^7.0.2",
|
|
38
38
|
"vitest": "4.1.10",
|
|
39
|
-
"@internal/lint": "0.0.129",
|
|
40
39
|
"@internal/types-builder": "0.0.104",
|
|
40
|
+
"@internal/lint": "0.0.129",
|
|
41
41
|
"@internal/auth": "0.0.19"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|