@mastra/auth-workos 1.6.5-alpha.0 → 1.6.5

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.
Files changed (2) hide show
  1. package/README.md +13 -116
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,140 +1,37 @@
1
1
  # @mastra/auth-workos
2
2
 
3
- A WorkOS integration for Mastra that supports authentication, role-based access control (RBAC), and Fine-Grained Authorization (FGA).
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
- // Initialize with environment variables
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
- With `trustJwtClaims: true`, Mastra can authenticate verified bearer tokens from a WorkOS custom JWT template even when `workos.userManagement.getUser()` is not the right lookup path, such as machine-to-machine or service-account tokens.
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
- ## API
28
+ - [WorkOS integration guide](https://mastra.ai/integrations/auth/workos)
29
+ - [WorkOS provider reference](https://mastra.ai/reference/auth/workos)
133
30
 
134
- ### `authenticateToken(token: string, request): Promise<WorkOSUser | null>`
31
+ ## Changelog
135
32
 
136
- Verifies a JWT token using WorkOS JWKS and returns the user information if valid.
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
- ### `authorizeUser(user: WorkOSUser, request): Promise<boolean>`
35
+ ## Support
139
36
 
140
- Authorizes an authenticated WorkOS user. By default, this returns `true` when the user has the required identifiers. Override this method in a subclass if you need stricter authorization.
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.0",
3
+ "version": "1.6.5",
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.0"
26
+ "@mastra/auth": "1.1.3"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "hono": "^4.0.0"
@@ -36,9 +36,9 @@
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
- "@internal/types-builder": "0.0.104",
41
- "@internal/auth": "0.0.19"
39
+ "@internal/lint": "0.0.130",
40
+ "@internal/types-builder": "0.0.105",
41
+ "@internal/auth": "0.0.20"
42
42
  },
43
43
  "files": [
44
44
  "dist"