workos 0.9.0 → 0.10.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 +5 -6
- package/dist/bin.js +39 -14
- package/dist/bin.js.map +1 -1
- package/dist/commands/install-skill.d.ts +0 -1
- package/dist/commands/install-skill.js +2 -10
- package/dist/commands/install-skill.js.map +1 -1
- package/dist/commands/list-skills.d.ts +4 -0
- package/dist/commands/list-skills.js +52 -0
- package/dist/commands/list-skills.js.map +1 -0
- package/dist/commands/login.d.ts +8 -0
- package/dist/commands/login.js +41 -1
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/uninstall-skill.d.ts +11 -0
- package/dist/commands/uninstall-skill.js +116 -0
- package/dist/commands/uninstall-skill.js.map +1 -0
- package/dist/integrations/dotnet/index.js +7 -12
- package/dist/integrations/dotnet/index.js.map +1 -1
- package/dist/integrations/elixir/index.js +7 -13
- package/dist/integrations/elixir/index.js.map +1 -1
- package/dist/integrations/go/index.js +5 -11
- package/dist/integrations/go/index.js.map +1 -1
- package/dist/integrations/python/index.js +7 -13
- package/dist/integrations/python/index.js.map +1 -1
- package/dist/integrations/ruby/index.js +9 -14
- package/dist/integrations/ruby/index.js.map +1 -1
- package/dist/lib/agent-interface.js +5 -4
- package/dist/lib/agent-interface.js.map +1 -1
- package/dist/lib/agent-runner.js +24 -19
- package/dist/lib/agent-runner.js.map +1 -1
- package/dist/utils/help-json.js +55 -21
- package/dist/utils/help-json.js.map +1 -1
- package/package.json +2 -3
- package/.claude-plugin/plugin.json +0 -13
- package/skills/workos-authkit-base/SKILL.md +0 -123
- package/skills/workos-authkit-nextjs/SKILL.md +0 -247
- package/skills/workos-authkit-react/SKILL.md +0 -100
- package/skills/workos-authkit-react-router/SKILL.md +0 -117
- package/skills/workos-authkit-sveltekit/SKILL.md +0 -208
- package/skills/workos-authkit-tanstack-start/SKILL.md +0 -314
- package/skills/workos-authkit-vanilla-js/SKILL.md +0 -92
- package/skills/workos-dotnet/SKILL.md +0 -163
- package/skills/workos-elixir/SKILL.md +0 -231
- package/skills/workos-go/SKILL.md +0 -226
- package/skills/workos-kotlin/SKILL.md +0 -195
- package/skills/workos-management/SKILL.md +0 -250
- package/skills/workos-node/SKILL.md +0 -197
- package/skills/workos-php/SKILL.md +0 -160
- package/skills/workos-php-laravel/SKILL.md +0 -182
- package/skills/workos-python/SKILL.md +0 -193
- package/skills/workos-ruby/SKILL.md +0 -198
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: workos-authkit-tanstack-start
|
|
3
|
-
description: Integrate WorkOS AuthKit with TanStack Start applications. Full-stack TypeScript with server functions. Use when project uses TanStack Start, @tanstack/start, or vinxi.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# WorkOS AuthKit for TanStack Start
|
|
7
|
-
|
|
8
|
-
## Decision Tree
|
|
9
|
-
|
|
10
|
-
```
|
|
11
|
-
1. Fetch README (BLOCKING)
|
|
12
|
-
├── Extract package name from install command
|
|
13
|
-
└── README is source of truth for ALL code patterns
|
|
14
|
-
|
|
15
|
-
2. Detect directory structure
|
|
16
|
-
├── src/ (TanStack Start v1.132+, default)
|
|
17
|
-
└── app/ (legacy vinxi-based projects)
|
|
18
|
-
|
|
19
|
-
3. Follow README install/setup exactly
|
|
20
|
-
└── Do not invent commands or patterns
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Fetch SDK Documentation (BLOCKING)
|
|
24
|
-
|
|
25
|
-
**STOP - Do not proceed until complete.**
|
|
26
|
-
|
|
27
|
-
WebFetch: `https://raw.githubusercontent.com/workos/authkit-tanstack-start/main/README.md`
|
|
28
|
-
|
|
29
|
-
From README, extract:
|
|
30
|
-
|
|
31
|
-
1. Package name: `@workos/authkit-tanstack-react-start`
|
|
32
|
-
2. Use that exact name for all imports
|
|
33
|
-
|
|
34
|
-
**README overrides this skill if conflict.**
|
|
35
|
-
|
|
36
|
-
## Pre-Flight Checklist
|
|
37
|
-
|
|
38
|
-
- [ ] README fetched and package name extracted
|
|
39
|
-
- [ ] `@tanstack/start` or `@tanstack/react-start` in package.json
|
|
40
|
-
- [ ] Identify directory structure: `src/` (modern) or `app/` (legacy)
|
|
41
|
-
- [ ] Environment variables set (see below)
|
|
42
|
-
|
|
43
|
-
## Directory Structure Detection
|
|
44
|
-
|
|
45
|
-
**Modern TanStack Start (v1.132+)** uses `src/`:
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
src/
|
|
49
|
-
├── start.ts # Middleware config (CRITICAL)
|
|
50
|
-
├── router.tsx # Router setup
|
|
51
|
-
├── routes/
|
|
52
|
-
│ ├── __root.tsx # Root layout
|
|
53
|
-
│ ├── api.auth.callback.tsx # OAuth callback (flat route)
|
|
54
|
-
│ └── ...
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
**Legacy (vinxi-based)** uses `app/`:
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
-
app/
|
|
61
|
-
├── start.ts or router.tsx
|
|
62
|
-
├── routes/
|
|
63
|
-
│ └── api/auth/callback.tsx # OAuth callback (nested route)
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
**Detection:**
|
|
67
|
-
|
|
68
|
-
```bash
|
|
69
|
-
ls src/routes 2>/dev/null && echo "Modern (src/)" || echo "Legacy (app/)"
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Environment Variables
|
|
73
|
-
|
|
74
|
-
| Variable | Format | Required |
|
|
75
|
-
| ------------------------ | ------------ | -------- |
|
|
76
|
-
| `WORKOS_API_KEY` | `sk_...` | Yes |
|
|
77
|
-
| `WORKOS_CLIENT_ID` | `client_...` | Yes |
|
|
78
|
-
| `WORKOS_REDIRECT_URI` | Full URL | Yes |
|
|
79
|
-
| `WORKOS_COOKIE_PASSWORD` | 32+ chars | Yes |
|
|
80
|
-
|
|
81
|
-
Generate password if missing: `openssl rand -base64 32`
|
|
82
|
-
|
|
83
|
-
Default redirect URI: `http://localhost:3000/api/auth/callback`
|
|
84
|
-
|
|
85
|
-
## Middleware Configuration (CRITICAL)
|
|
86
|
-
|
|
87
|
-
**authkitMiddleware MUST be configured or auth will fail silently.**
|
|
88
|
-
|
|
89
|
-
**WARNING: Do NOT add middleware to `createRouter()` in `router.tsx` or `app.tsx`. That is TanStack Router (client-side only). Server middleware belongs in `start.ts` using `requestMiddleware`.**
|
|
90
|
-
|
|
91
|
-
### If `start.ts` already exists
|
|
92
|
-
|
|
93
|
-
Read the existing file first. Add `authkitMiddleware` to the existing `requestMiddleware` array (or create the array if missing). Preserve the existing export style. Do not rewrite the file from scratch.
|
|
94
|
-
|
|
95
|
-
### If `start.ts` does not exist
|
|
96
|
-
|
|
97
|
-
Create `src/start.ts` (or `app/start.ts` for legacy) using `createStart`:
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
import { createStart } from '@tanstack/react-start';
|
|
101
|
-
import { authkitMiddleware } from '@workos/authkit-tanstack-react-start';
|
|
102
|
-
|
|
103
|
-
export const startInstance = createStart(() => ({
|
|
104
|
-
requestMiddleware: [authkitMiddleware()],
|
|
105
|
-
}));
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
**Two things matter here:**
|
|
109
|
-
|
|
110
|
-
1. **Named export `startInstance`** — the build plugin generates `import type { startInstance }` from this file. A `default` export will cause a build error.
|
|
111
|
-
2. **`createStart` takes a function** returning the options object, not the options directly. `createStart({ ... })` will fail.
|
|
112
|
-
|
|
113
|
-
**WARNING: Do NOT add middleware to `createRouter()` in `router.tsx` or `app.tsx`. That is TanStack Router (client-side only). Server middleware belongs in `start.ts` using `requestMiddleware`.**
|
|
114
|
-
|
|
115
|
-
## Callback Route (CRITICAL)
|
|
116
|
-
|
|
117
|
-
Path must match `WORKOS_REDIRECT_URI`. For `/api/auth/callback`:
|
|
118
|
-
|
|
119
|
-
**Modern (flat routes):** `src/routes/api.auth.callback.tsx`
|
|
120
|
-
**Legacy (nested routes):** `app/routes/api/auth/callback.tsx`
|
|
121
|
-
|
|
122
|
-
```typescript
|
|
123
|
-
import { createFileRoute } from '@tanstack/react-router';
|
|
124
|
-
import { handleCallbackRoute } from '@workos/authkit-tanstack-react-start';
|
|
125
|
-
|
|
126
|
-
export const Route = createFileRoute('/api/auth/callback')({
|
|
127
|
-
server: {
|
|
128
|
-
handlers: {
|
|
129
|
-
GET: handleCallbackRoute(),
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
**Key points:**
|
|
136
|
-
|
|
137
|
-
- Use `handleCallbackRoute()` - do not write custom OAuth logic
|
|
138
|
-
- Route path string must match the URI path exactly
|
|
139
|
-
- This is a server-only route (no component needed)
|
|
140
|
-
|
|
141
|
-
## Protected Routes
|
|
142
|
-
|
|
143
|
-
Use `getAuth()` in route loaders to check authentication:
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
import { createFileRoute, redirect } from '@tanstack/react-router';
|
|
147
|
-
import { getAuth, getSignInUrl } from '@workos/authkit-tanstack-react-start';
|
|
148
|
-
|
|
149
|
-
export const Route = createFileRoute('/dashboard')({
|
|
150
|
-
loader: async () => {
|
|
151
|
-
const { user } = await getAuth();
|
|
152
|
-
if (!user) {
|
|
153
|
-
const signInUrl = await getSignInUrl();
|
|
154
|
-
throw redirect({ href: signInUrl });
|
|
155
|
-
}
|
|
156
|
-
return { user };
|
|
157
|
-
},
|
|
158
|
-
component: Dashboard,
|
|
159
|
-
});
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
## Sign Out Route
|
|
163
|
-
|
|
164
|
-
```typescript
|
|
165
|
-
import { createFileRoute, redirect } from '@tanstack/react-router';
|
|
166
|
-
import { signOut } from '@workos/authkit-tanstack-react-start';
|
|
167
|
-
|
|
168
|
-
export const Route = createFileRoute('/signout')({
|
|
169
|
-
loader: async () => {
|
|
170
|
-
await signOut();
|
|
171
|
-
throw redirect({ href: '/' });
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
## Client-Side Hooks (Optional)
|
|
177
|
-
|
|
178
|
-
Only needed if you want reactive auth state in components.
|
|
179
|
-
|
|
180
|
-
**1. Add AuthKitProvider to root:**
|
|
181
|
-
|
|
182
|
-
```typescript
|
|
183
|
-
// src/routes/__root.tsx
|
|
184
|
-
import { AuthKitProvider } from '@workos/authkit-tanstack-react-start/client';
|
|
185
|
-
|
|
186
|
-
function RootComponent() {
|
|
187
|
-
return (
|
|
188
|
-
<AuthKitProvider>
|
|
189
|
-
<Outlet />
|
|
190
|
-
</AuthKitProvider>
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
**2. Use hooks in components:**
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
import { useAuth } from '@workos/authkit-tanstack-react-start/client';
|
|
199
|
-
|
|
200
|
-
function Profile() {
|
|
201
|
-
const { user, isLoading } = useAuth();
|
|
202
|
-
// ...
|
|
203
|
-
}
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
**Note:** Server-side `getAuth()` is preferred for most use cases.
|
|
207
|
-
|
|
208
|
-
## Finalize (REQUIRED before declaring success)
|
|
209
|
-
|
|
210
|
-
After creating/editing all files, run these steps in order. Skipping them is the most common cause of build failures.
|
|
211
|
-
|
|
212
|
-
### 1. Regenerate the route tree
|
|
213
|
-
|
|
214
|
-
Adding new route files (callback, signout, etc.) makes the existing `routeTree.gen.ts` stale. The build will fail with type errors about missing routes until it is regenerated.
|
|
215
|
-
|
|
216
|
-
```bash
|
|
217
|
-
pnpm build 2>/dev/null || npx tsr generate
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
The build itself triggers route tree regeneration. If it fails for other reasons, use `tsr generate` directly.
|
|
221
|
-
|
|
222
|
-
### 2. Ensure Vite type declarations exist
|
|
223
|
-
|
|
224
|
-
TanStack Start projects import CSS with `import styles from './styles.css?url'`. Without Vite's type declarations, TypeScript will error on these imports. Check if `src/vite-env.d.ts` (or `app/vite-env.d.ts`) exists — if not, create it now (before attempting the build):
|
|
225
|
-
|
|
226
|
-
```typescript
|
|
227
|
-
/// <reference types="vite/client" />
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
### 3. Verify the build
|
|
231
|
-
|
|
232
|
-
```bash
|
|
233
|
-
pnpm build
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
Do not skip this step. If the build fails, fix the errors before finishing. Common causes:
|
|
237
|
-
|
|
238
|
-
- Stale route tree → re-run step 1
|
|
239
|
-
- Missing Vite types → re-run step 2
|
|
240
|
-
- Wrong import paths → check package name is `@workos/authkit-tanstack-react-start`
|
|
241
|
-
|
|
242
|
-
## Verification Checklist (ALL MUST PASS)
|
|
243
|
-
|
|
244
|
-
Run these commands to confirm integration. **Do not mark complete until all pass:**
|
|
245
|
-
|
|
246
|
-
```bash
|
|
247
|
-
# 1. Check authkitMiddleware is configured
|
|
248
|
-
grep -r "authkitMiddleware" src/ app/ 2>/dev/null || echo "FAIL: Middleware not configured"
|
|
249
|
-
|
|
250
|
-
# 2. Check callback route exists
|
|
251
|
-
find src/routes app/routes -name "*callback*" 2>/dev/null
|
|
252
|
-
|
|
253
|
-
# 3. Check environment variables
|
|
254
|
-
grep -c "WORKOS_" .env 2>/dev/null || echo "FAIL: No env vars found"
|
|
255
|
-
|
|
256
|
-
# 4. Build succeeds
|
|
257
|
-
pnpm build
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
**If check #1 fails:** authkitMiddleware must be in src/start.ts (or app/start.ts for legacy) requestMiddleware array. Auth will fail silently without it.
|
|
261
|
-
|
|
262
|
-
## Error Recovery
|
|
263
|
-
|
|
264
|
-
### "AuthKit middleware is not configured"
|
|
265
|
-
|
|
266
|
-
**Cause:** `authkitMiddleware()` not in start.ts
|
|
267
|
-
**Fix:** Create/update `src/start.ts` with middleware config
|
|
268
|
-
**Verify:** `grep -r "authkitMiddleware" src/`
|
|
269
|
-
|
|
270
|
-
### "Module not found" for SDK
|
|
271
|
-
|
|
272
|
-
**Cause:** Wrong package name or not installed
|
|
273
|
-
**Fix:** `pnpm add @workos/authkit-tanstack-react-start`
|
|
274
|
-
**Verify:** `ls node_modules/@workos/authkit-tanstack-react-start`
|
|
275
|
-
|
|
276
|
-
### Callback 404
|
|
277
|
-
|
|
278
|
-
**Cause:** Route file path doesn't match WORKOS_REDIRECT_URI
|
|
279
|
-
**Fix:**
|
|
280
|
-
|
|
281
|
-
- URI `/api/auth/callback` → file `src/routes/api.auth.callback.tsx` (flat) or `app/routes/api/auth/callback.tsx` (nested)
|
|
282
|
-
- Route path string in `createFileRoute()` must match exactly
|
|
283
|
-
|
|
284
|
-
### getAuth returns undefined user
|
|
285
|
-
|
|
286
|
-
**Cause:** Middleware not configured or not running
|
|
287
|
-
**Fix:** Ensure `authkitMiddleware()` is in start.ts requestMiddleware array
|
|
288
|
-
|
|
289
|
-
### "Cookie password too short"
|
|
290
|
-
|
|
291
|
-
**Cause:** WORKOS_COOKIE_PASSWORD < 32 chars
|
|
292
|
-
**Fix:** `openssl rand -base64 32`, update .env
|
|
293
|
-
|
|
294
|
-
### Build fails with route type errors
|
|
295
|
-
|
|
296
|
-
**Cause:** Route tree not regenerated after adding routes
|
|
297
|
-
**Fix:** `pnpm dev` to regenerate `routeTree.gen.ts`
|
|
298
|
-
|
|
299
|
-
## SDK Exports Reference
|
|
300
|
-
|
|
301
|
-
**Server (main export):**
|
|
302
|
-
|
|
303
|
-
- `authkitMiddleware()` - Request middleware
|
|
304
|
-
- `handleCallbackRoute()` - OAuth callback handler
|
|
305
|
-
- `getAuth()` - Get current session
|
|
306
|
-
- `signOut()` - Sign out user
|
|
307
|
-
- `getSignInUrl()` / `getSignUpUrl()` - Auth URLs
|
|
308
|
-
- `switchToOrganization()` - Change org context
|
|
309
|
-
|
|
310
|
-
**Client (`/client` subpath):**
|
|
311
|
-
|
|
312
|
-
- `AuthKitProvider` - Context provider
|
|
313
|
-
- `useAuth()` - Auth state hook
|
|
314
|
-
- `useAccessToken()` - Token management
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: workos-authkit-vanilla-js
|
|
3
|
-
description: Integrate WorkOS AuthKit with vanilla JavaScript applications. No framework required, browser-only. Use when project is plain HTML/JS, doesn't use React/Vue/etc, or mentions vanilla JavaScript authentication.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# WorkOS AuthKit for Vanilla JavaScript
|
|
7
|
-
|
|
8
|
-
## Decision Tree
|
|
9
|
-
|
|
10
|
-
### Step 1: Fetch README (BLOCKING)
|
|
11
|
-
|
|
12
|
-
WebFetch: `https://raw.githubusercontent.com/workos/authkit-js/main/README.md`
|
|
13
|
-
|
|
14
|
-
**README is source of truth.** If this skill conflicts, follow README.
|
|
15
|
-
|
|
16
|
-
### Step 2: Detect Project Type
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
Has package.json with build tool (Vite, webpack, Parcel)?
|
|
20
|
-
YES -> Bundled project (npm install)
|
|
21
|
-
NO -> CDN/Static project (script tag)
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### Step 3: Follow README Installation
|
|
25
|
-
|
|
26
|
-
- **Bundled**: Use package manager install from README
|
|
27
|
-
- **CDN**: Use unpkg script tag from README
|
|
28
|
-
|
|
29
|
-
### Step 4: Implement Per README
|
|
30
|
-
|
|
31
|
-
Follow README examples for:
|
|
32
|
-
|
|
33
|
-
- Client initialization
|
|
34
|
-
- Sign in/out handlers
|
|
35
|
-
- User state management
|
|
36
|
-
|
|
37
|
-
## Critical API Quirk
|
|
38
|
-
|
|
39
|
-
`createClient()` is **async** - returns a Promise, not a client directly.
|
|
40
|
-
|
|
41
|
-
```javascript
|
|
42
|
-
// CORRECT
|
|
43
|
-
const authkit = await createClient(clientId);
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Verification Checklist (ALL MUST PASS)
|
|
47
|
-
|
|
48
|
-
Run these commands to confirm integration. **Do not mark complete until all pass:**
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
# 1. Check SDK is available (bundled or CDN)
|
|
52
|
-
grep -r "createClient\|WorkOS" src/ *.html 2>/dev/null || echo "FAIL: SDK not found"
|
|
53
|
-
|
|
54
|
-
# 2. Check createClient uses await
|
|
55
|
-
grep -rn "await createClient" src/ *.js *.html 2>/dev/null || echo "FAIL: createClient must be awaited"
|
|
56
|
-
|
|
57
|
-
# 3. Check sign-in is on user gesture (click handler)
|
|
58
|
-
grep -rn "signIn\|sign_in" src/ *.js *.html 2>/dev/null
|
|
59
|
-
|
|
60
|
-
# 4. Build succeeds (bundled projects only)
|
|
61
|
-
pnpm build 2>/dev/null || echo "CDN project — verify manually in browser"
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
**If check #2 fails:** createClient() is async and must be awaited. Using it without await returns a Promise, not a client.
|
|
65
|
-
|
|
66
|
-
## Environment Variables
|
|
67
|
-
|
|
68
|
-
**Bundled projects only:**
|
|
69
|
-
|
|
70
|
-
- Vite: `VITE_WORKOS_CLIENT_ID`
|
|
71
|
-
- Webpack: `REACT_APP_WORKOS_CLIENT_ID` or custom
|
|
72
|
-
- No `WORKOS_API_KEY` needed (client-side SDK)
|
|
73
|
-
|
|
74
|
-
## Error Recovery
|
|
75
|
-
|
|
76
|
-
| Error | Cause | Fix |
|
|
77
|
-
| -------------------------------- | ------------------- | ------------------------------------------------------ |
|
|
78
|
-
| `WorkOS is not defined` | CDN not loaded | Add script to `<head>` before your code |
|
|
79
|
-
| `createClient is not a function` | Wrong import | npm: check import path; CDN: use `WorkOS.createClient` |
|
|
80
|
-
| `clientId is required` | Undefined env var | Check env prefix matches build tool |
|
|
81
|
-
| CORS errors | `file://` protocol | Use local dev server (`npx serve`) |
|
|
82
|
-
| Popup blocked | Not user gesture | Call `signIn()` only from click handler |
|
|
83
|
-
| Auth state lost | Token not persisted | Check localStorage in dev tools |
|
|
84
|
-
|
|
85
|
-
## Task Flow
|
|
86
|
-
|
|
87
|
-
1. **preflight**: Fetch README, detect project type, verify env vars
|
|
88
|
-
2. **install**: Add SDK per project type
|
|
89
|
-
3. **callback**: SDK handles internally (no server route needed)
|
|
90
|
-
4. **provider**: Initialize client with `await createClient()`
|
|
91
|
-
5. **ui**: Add auth buttons and state display
|
|
92
|
-
6. **verify**: Build (if bundled), check console
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: workos-dotnet
|
|
3
|
-
description: Integrate WorkOS AuthKit with .NET (ASP.NET Core). Backend authentication with DI registration, auth endpoints, and appsettings configuration.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# WorkOS AuthKit for .NET (ASP.NET Core)
|
|
7
|
-
|
|
8
|
-
## Step 1: Fetch SDK Documentation (BLOCKING)
|
|
9
|
-
|
|
10
|
-
**STOP. Do not proceed until complete.**
|
|
11
|
-
|
|
12
|
-
WebFetch: `https://raw.githubusercontent.com/workos/workos-dotnet/main/README.md`
|
|
13
|
-
|
|
14
|
-
The README is the source of truth for SDK API usage. If this skill conflicts with README, follow README.
|
|
15
|
-
|
|
16
|
-
## Step 2: Pre-Flight Validation
|
|
17
|
-
|
|
18
|
-
### Project Structure
|
|
19
|
-
|
|
20
|
-
- Confirm a `*.csproj` file exists in the project root
|
|
21
|
-
- Detect project style:
|
|
22
|
-
- **Minimal API** (modern): `Program.cs` with `WebApplication.CreateBuilder()` — .NET 6+
|
|
23
|
-
- **Startup pattern** (older): `Startup.cs` with `ConfigureServices()` / `Configure()` — .NET 5 and earlier
|
|
24
|
-
|
|
25
|
-
This detection determines WHERE to register WorkOS services and middleware.
|
|
26
|
-
|
|
27
|
-
### Environment Variables
|
|
28
|
-
|
|
29
|
-
Check `appsettings.Development.json` for:
|
|
30
|
-
|
|
31
|
-
- `WORKOS_API_KEY` — starts with `sk_`
|
|
32
|
-
- `WORKOS_CLIENT_ID` — starts with `client_`
|
|
33
|
-
|
|
34
|
-
## Step 3: Install SDK
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
dotnet add package WorkOS.net
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
**Verify:** Check the `*.csproj` file contains a `<PackageReference Include="WorkOS.net"` entry.
|
|
41
|
-
|
|
42
|
-
If `dotnet` CLI is not available, stop and inform the user to install the .NET SDK.
|
|
43
|
-
|
|
44
|
-
## Step 4: Configure WorkOS Client
|
|
45
|
-
|
|
46
|
-
### Minimal API Pattern (Program.cs)
|
|
47
|
-
|
|
48
|
-
Add WorkOS configuration to `Program.cs`:
|
|
49
|
-
|
|
50
|
-
1. Read WorkOS settings from `IConfiguration`
|
|
51
|
-
2. Register the WorkOS client in the DI container
|
|
52
|
-
3. The WorkOS client needs API key for initialization
|
|
53
|
-
|
|
54
|
-
```csharp
|
|
55
|
-
// In Program.cs, after builder creation:
|
|
56
|
-
var workosApiKey = builder.Configuration["WorkOS:ApiKey"];
|
|
57
|
-
var workosClientId = builder.Configuration["WorkOS:ClientId"];
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### Startup Pattern (Startup.cs)
|
|
61
|
-
|
|
62
|
-
Add to `ConfigureServices()`:
|
|
63
|
-
|
|
64
|
-
1. Read WorkOS settings from `IConfiguration`
|
|
65
|
-
2. Register services
|
|
66
|
-
|
|
67
|
-
Choose the pattern that matches the detected project structure.
|
|
68
|
-
|
|
69
|
-
## Step 5: Create Authentication Endpoints
|
|
70
|
-
|
|
71
|
-
Create auth endpoints following the WorkOS AuthKit pattern. Use minimal API `app.MapGet()` for minimal API projects, or a Controller for Startup-pattern projects.
|
|
72
|
-
|
|
73
|
-
### Required Endpoints
|
|
74
|
-
|
|
75
|
-
**GET /auth/login** — Redirect to WorkOS AuthKit:
|
|
76
|
-
|
|
77
|
-
- Use the WorkOS SDK to generate an authorization URL
|
|
78
|
-
- Include `clientId`, `redirectUri`, and `provider: "authkit"` parameters
|
|
79
|
-
- Redirect the user to the authorization URL
|
|
80
|
-
|
|
81
|
-
**GET /auth/callback** — Handle OAuth callback:
|
|
82
|
-
|
|
83
|
-
- Extract `code` from query parameters
|
|
84
|
-
- Exchange authorization code for user profile using the WorkOS SDK
|
|
85
|
-
- Store user info in session or cookie
|
|
86
|
-
- Redirect to home page
|
|
87
|
-
|
|
88
|
-
**GET /auth/logout** — Clear session:
|
|
89
|
-
|
|
90
|
-
- Clear the authentication session/cookie
|
|
91
|
-
- Redirect to home page
|
|
92
|
-
|
|
93
|
-
### Session Management
|
|
94
|
-
|
|
95
|
-
Use ASP.NET Core's built-in session or cookie authentication:
|
|
96
|
-
|
|
97
|
-
```csharp
|
|
98
|
-
// Enable session middleware in Program.cs
|
|
99
|
-
builder.Services.AddDistributedMemoryCache();
|
|
100
|
-
builder.Services.AddSession();
|
|
101
|
-
// ...
|
|
102
|
-
app.UseSession();
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
## Step 6: Environment Setup
|
|
106
|
-
|
|
107
|
-
Configure `appsettings.Development.json` with WorkOS credentials:
|
|
108
|
-
|
|
109
|
-
```json
|
|
110
|
-
{
|
|
111
|
-
"WorkOS": {
|
|
112
|
-
"ApiKey": "<WORKOS_API_KEY value>",
|
|
113
|
-
"ClientId": "<WORKOS_CLIENT_ID value>",
|
|
114
|
-
"RedirectUri": "http://localhost:5000/auth/callback"
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
Use the actual credential values provided in the environment context.
|
|
120
|
-
|
|
121
|
-
**Important:** Do NOT put secrets in `appsettings.json` (committed to git). Use `appsettings.Development.json` (gitignored) or `dotnet user-secrets`.
|
|
122
|
-
|
|
123
|
-
## Step 7: Verification
|
|
124
|
-
|
|
125
|
-
Run these checks — **do not mark complete until all pass:**
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
# 1. Check WorkOS.net is in csproj
|
|
129
|
-
grep -i "WorkOS" *.csproj
|
|
130
|
-
|
|
131
|
-
# 2. Check auth endpoints exist
|
|
132
|
-
grep -r "auth/login\|auth/callback\|auth/logout" *.cs
|
|
133
|
-
|
|
134
|
-
# 3. Build succeeds
|
|
135
|
-
dotnet build
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
**If build fails:** Read the error output carefully. Common issues:
|
|
139
|
-
|
|
140
|
-
- Missing `using` statements for WorkOS namespaces
|
|
141
|
-
- Incorrect DI registration order
|
|
142
|
-
- Missing session/cookie middleware registration
|
|
143
|
-
|
|
144
|
-
## Error Recovery
|
|
145
|
-
|
|
146
|
-
### "dotnet: command not found"
|
|
147
|
-
|
|
148
|
-
- .NET SDK is not installed. Inform the user to install from https://dotnet.microsoft.com/download
|
|
149
|
-
|
|
150
|
-
### NuGet restore failures
|
|
151
|
-
|
|
152
|
-
- Check internet connectivity
|
|
153
|
-
- Try `dotnet restore` explicitly before `dotnet build`
|
|
154
|
-
|
|
155
|
-
### "No project file found"
|
|
156
|
-
|
|
157
|
-
- Ensure you're in the correct directory with a `*.csproj` file
|
|
158
|
-
|
|
159
|
-
### Build errors after integration
|
|
160
|
-
|
|
161
|
-
- Check that all `using` statements are correct
|
|
162
|
-
- Verify DI registration order (services before middleware)
|
|
163
|
-
- Ensure `app.UseSession()` is called before mapping auth endpoints
|