workos 0.4.5 → 0.5.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/dist/bin.js +32 -3
- package/dist/bin.js.map +1 -1
- package/dist/commands/doctor.d.ts +10 -0
- package/dist/commands/doctor.js +30 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/doctor/checks/connectivity.d.ts +2 -0
- package/dist/doctor/checks/connectivity.js +35 -0
- package/dist/doctor/checks/connectivity.js.map +1 -0
- package/dist/doctor/checks/dashboard.d.ts +3 -0
- package/dist/doctor/checks/dashboard.js +123 -0
- package/dist/doctor/checks/dashboard.js.map +1 -0
- package/dist/doctor/checks/environment.d.ts +2 -0
- package/dist/doctor/checks/environment.js +68 -0
- package/dist/doctor/checks/environment.js.map +1 -0
- package/dist/doctor/checks/framework.d.ts +2 -0
- package/dist/doctor/checks/framework.js +75 -0
- package/dist/doctor/checks/framework.js.map +1 -0
- package/dist/doctor/checks/runtime.d.ts +2 -0
- package/dist/doctor/checks/runtime.js +20 -0
- package/dist/doctor/checks/runtime.js.map +1 -0
- package/dist/doctor/checks/sdk.d.ts +2 -0
- package/dist/doctor/checks/sdk.js +111 -0
- package/dist/doctor/checks/sdk.js.map +1 -0
- package/dist/doctor/clipboard.d.ts +1 -0
- package/dist/doctor/clipboard.js +43 -0
- package/dist/doctor/clipboard.js.map +1 -0
- package/dist/doctor/index.d.ts +6 -0
- package/dist/doctor/index.js +94 -0
- package/dist/doctor/index.js.map +1 -0
- package/dist/doctor/issues.d.ts +58 -0
- package/dist/doctor/issues.js +134 -0
- package/dist/doctor/issues.js.map +1 -0
- package/dist/doctor/json-output.d.ts +2 -0
- package/dist/doctor/json-output.js +4 -0
- package/dist/doctor/json-output.js.map +1 -0
- package/dist/doctor/output.d.ts +5 -0
- package/dist/doctor/output.js +149 -0
- package/dist/doctor/output.js.map +1 -0
- package/dist/doctor/types.d.ts +105 -0
- package/dist/doctor/types.js +2 -0
- package/dist/doctor/types.js.map +1 -0
- package/dist/integrations/dotnet/index.d.ts +8 -0
- package/dist/integrations/dotnet/index.js +163 -0
- package/dist/integrations/dotnet/index.js.map +1 -0
- package/dist/integrations/elixir/index.d.ts +8 -0
- package/dist/integrations/elixir/index.js +152 -0
- package/dist/integrations/elixir/index.js.map +1 -0
- package/dist/integrations/go/index.d.ts +11 -0
- package/dist/integrations/go/index.js +220 -0
- package/dist/integrations/go/index.js.map +1 -0
- package/dist/integrations/kotlin/index.d.ts +4 -0
- package/dist/integrations/kotlin/index.js +53 -0
- package/dist/integrations/kotlin/index.js.map +1 -0
- package/dist/integrations/nextjs/index.d.ts +4 -0
- package/dist/integrations/nextjs/index.js +90 -0
- package/dist/integrations/nextjs/index.js.map +1 -0
- package/dist/integrations/nextjs/utils.d.ts +8 -0
- package/dist/integrations/nextjs/utils.js +53 -0
- package/dist/integrations/nextjs/utils.js.map +1 -0
- package/dist/integrations/node/index.d.ts +4 -0
- package/dist/integrations/node/index.js +52 -0
- package/dist/integrations/node/index.js.map +1 -0
- package/dist/integrations/php/index.d.ts +4 -0
- package/dist/integrations/php/index.js +51 -0
- package/dist/integrations/php/index.js.map +1 -0
- package/dist/integrations/php-laravel/index.d.ts +4 -0
- package/dist/integrations/php-laravel/index.js +51 -0
- package/dist/integrations/php-laravel/index.js.map +1 -0
- package/dist/integrations/python/index.d.ts +9 -0
- package/dist/integrations/python/index.js +254 -0
- package/dist/integrations/python/index.js.map +1 -0
- package/dist/integrations/react/index.d.ts +4 -0
- package/dist/integrations/react/index.js +49 -0
- package/dist/integrations/react/index.js.map +1 -0
- package/dist/integrations/react-router/index.d.ts +4 -0
- package/dist/integrations/react-router/index.js +94 -0
- package/dist/integrations/react-router/index.js.map +1 -0
- package/dist/integrations/react-router/utils.d.ts +10 -0
- package/dist/integrations/react-router/utils.js +146 -0
- package/dist/integrations/react-router/utils.js.map +1 -0
- package/dist/integrations/ruby/index.d.ts +8 -0
- package/dist/integrations/ruby/index.js +142 -0
- package/dist/integrations/ruby/index.js.map +1 -0
- package/dist/integrations/sveltekit/index.d.ts +4 -0
- package/dist/integrations/sveltekit/index.js +50 -0
- package/dist/integrations/sveltekit/index.js.map +1 -0
- package/dist/integrations/tanstack-start/index.d.ts +4 -0
- package/dist/integrations/tanstack-start/index.js +51 -0
- package/dist/integrations/tanstack-start/index.js.map +1 -0
- package/dist/integrations/vanilla-js/index.d.ts +4 -0
- package/dist/integrations/vanilla-js/index.js +49 -0
- package/dist/integrations/vanilla-js/index.js.map +1 -0
- package/dist/lib/agent-interface.js +66 -1
- package/dist/lib/agent-interface.js.map +1 -1
- package/dist/lib/config.d.ts +32 -58
- package/dist/lib/config.js +19 -70
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/constants.d.ts +17 -14
- package/dist/lib/constants.js +12 -31
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/framework-config.d.ts +13 -4
- package/dist/lib/framework-config.js.map +1 -1
- package/dist/lib/language-detection.d.ts +20 -0
- package/dist/lib/language-detection.js +96 -0
- package/dist/lib/language-detection.js.map +1 -0
- package/dist/lib/port-detection.js +4 -2
- package/dist/lib/port-detection.js.map +1 -1
- package/dist/lib/registry.d.ts +43 -0
- package/dist/lib/registry.js +96 -0
- package/dist/lib/registry.js.map +1 -0
- package/dist/lib/run-with-core.js +70 -26
- package/dist/lib/run-with-core.js.map +1 -1
- package/dist/lib/validation/validator.js +43 -13
- package/dist/lib/validation/validator.js.map +1 -1
- package/dist/nextjs/nextjs-installer-agent.d.ts +3 -4
- package/dist/nextjs/nextjs-installer-agent.js +3 -94
- package/dist/nextjs/nextjs-installer-agent.js.map +1 -1
- package/dist/nextjs/utils.d.ts +4 -8
- package/dist/nextjs/utils.js +4 -52
- package/dist/nextjs/utils.js.map +1 -1
- package/dist/react/react-installer-agent.d.ts +4 -2
- package/dist/react/react-installer-agent.js +4 -46
- package/dist/react/react-installer-agent.js.map +1 -1
- package/dist/react-router/react-router-installer-agent.d.ts +2 -4
- package/dist/react-router/react-router-installer-agent.js +2 -100
- package/dist/react-router/react-router-installer-agent.js.map +1 -1
- package/dist/react-router/utils.d.ts +2 -17
- package/dist/react-router/utils.js +2 -207
- package/dist/react-router/utils.js.map +1 -1
- package/dist/tanstack-start/tanstack-start-installer-agent.d.ts +4 -2
- package/dist/tanstack-start/tanstack-start-installer-agent.js +4 -48
- package/dist/tanstack-start/tanstack-start-installer-agent.js.map +1 -1
- package/dist/vanilla-js/vanilla-js-installer-agent.d.ts +4 -2
- package/dist/vanilla-js/vanilla-js-installer-agent.js +4 -46
- package/dist/vanilla-js/vanilla-js-installer-agent.js.map +1 -1
- package/package.json +6 -5
- package/skills/workos-authkit-nextjs/SKILL.md +41 -11
- package/skills/workos-authkit-sveltekit/SKILL.md +160 -0
- package/skills/workos-dotnet/SKILL.md +163 -0
- package/skills/workos-elixir/SKILL.md +194 -0
- package/skills/workos-go/SKILL.md +191 -0
- package/skills/workos-kotlin/SKILL.md +161 -0
- package/skills/workos-node/SKILL.md +164 -0
- package/skills/workos-php/SKILL.md +127 -0
- package/skills/workos-php-laravel/SKILL.md +147 -0
- package/skills/workos-python/SKILL.md +159 -0
- package/skills/workos-ruby/SKILL.md +163 -0
|
@@ -1,47 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
metadata: {
|
|
6
|
-
name: 'Vanilla JavaScript',
|
|
7
|
-
integration: Integration.vanillaJs,
|
|
8
|
-
docsUrl: 'https://workos.com/docs/user-management/authkit/javascript',
|
|
9
|
-
unsupportedVersionDocsUrl: 'https://workos.com/docs/user-management/authkit/javascript',
|
|
10
|
-
skillName: 'workos-authkit-vanilla-js',
|
|
11
|
-
},
|
|
12
|
-
detection: {
|
|
13
|
-
packageName: 'workos',
|
|
14
|
-
packageDisplayName: 'Vanilla JavaScript',
|
|
15
|
-
getVersion: () => undefined,
|
|
16
|
-
},
|
|
17
|
-
environment: {
|
|
18
|
-
uploadToHosting: false,
|
|
19
|
-
requiresApiKey: false, // Client-only
|
|
20
|
-
getEnvVars: (apiKey, clientId) => ({
|
|
21
|
-
WORKOS_CLIENT_ID: clientId, // Only client ID needed
|
|
22
|
-
}),
|
|
23
|
-
},
|
|
24
|
-
analytics: {
|
|
25
|
-
getTags: () => ({}),
|
|
26
|
-
},
|
|
27
|
-
prompts: {},
|
|
28
|
-
ui: {
|
|
29
|
-
successMessage: 'WorkOS AuthKit integration complete',
|
|
30
|
-
getOutroChanges: () => [
|
|
31
|
-
'Created WorkOS AuthKit integration',
|
|
32
|
-
'Added authentication to your JavaScript application',
|
|
33
|
-
'Set up login/logout functionality',
|
|
34
|
-
],
|
|
35
|
-
getOutroNextSteps: () => [
|
|
36
|
-
'Start your development server to test authentication',
|
|
37
|
-
'Visit the WorkOS Dashboard to manage users and settings',
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
export async function runVanillaJsInstallerAgent(options) {
|
|
42
|
-
if (options.debug) {
|
|
43
|
-
enableDebugLogs();
|
|
44
|
-
}
|
|
45
|
-
return runAgentInstaller(VANILLA_JS_AGENT_CONFIG, options);
|
|
46
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Import from 'src/integrations/vanilla-js/index.js' instead.
|
|
3
|
+
*/
|
|
4
|
+
export { run as runVanillaJsInstallerAgent, config as VANILLA_JS_AGENT_CONFIG, } from '../integrations/vanilla-js/index.js';
|
|
47
5
|
//# sourceMappingURL=vanilla-js-installer-agent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vanilla-js-installer-agent.js","sourceRoot":"","sources":["../../src/vanilla-js/vanilla-js-installer-agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vanilla-js-installer-agent.js","sourceRoot":"","sources":["../../src/vanilla-js/vanilla-js-installer-agent.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,GAAG,IAAI,0BAA0B,EACjC,MAAM,IAAI,uBAAuB,GAClC,MAAM,qCAAqC,CAAC","sourcesContent":["/**\n * @deprecated Import from 'src/integrations/vanilla-js/index.js' instead.\n */\nexport {\n run as runVanillaJsInstallerAgent,\n config as VANILLA_JS_AGENT_CONFIG,\n} from '../integrations/vanilla-js/index.js';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The Official Workos CLI",
|
|
6
6
|
"repository": {
|
|
@@ -73,8 +73,7 @@
|
|
|
73
73
|
"engines": {
|
|
74
74
|
"node": ">=20.20"
|
|
75
75
|
},
|
|
76
|
-
"
|
|
77
|
-
"license": "MIT",
|
|
76
|
+
"packageManager": "pnpm@10.28.2",
|
|
78
77
|
"scripts": {
|
|
79
78
|
"clean": "rm -rf ./dist",
|
|
80
79
|
"prebuild": "pnpm clean",
|
|
@@ -95,5 +94,7 @@
|
|
|
95
94
|
"eval:prune": "tsx tests/evals/index.ts prune",
|
|
96
95
|
"eval:logs": "tsx tests/evals/index.ts logs",
|
|
97
96
|
"eval:show": "tsx tests/evals/index.ts show"
|
|
98
|
-
}
|
|
99
|
-
|
|
97
|
+
},
|
|
98
|
+
"author": "WorkOS",
|
|
99
|
+
"license": "MIT"
|
|
100
|
+
}
|
|
@@ -35,21 +35,39 @@ Detect package manager, install SDK package from README.
|
|
|
35
35
|
|
|
36
36
|
**Verify:** SDK package exists in node_modules before continuing.
|
|
37
37
|
|
|
38
|
-
## Step 4:
|
|
38
|
+
## Step 4: Locate the app/ directory (BLOCKING)
|
|
39
|
+
|
|
40
|
+
**STOP. Do this before creating any files.**
|
|
41
|
+
|
|
42
|
+
Determine where the `app/` directory lives:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Check for src/app/ first, then root app/
|
|
46
|
+
ls src/app/ 2>/dev/null && echo "APP_DIR=src" || (ls app/ 2>/dev/null && echo "APP_DIR=root")
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Set `APP_DIR` for all subsequent steps. All middleware/proxy files MUST be created in `APP_DIR`:
|
|
50
|
+
|
|
51
|
+
- If `APP_DIR=src` → create files in `src/` (e.g., `src/proxy.ts`)
|
|
52
|
+
- If `APP_DIR=root` → create files at project root (e.g., `proxy.ts`)
|
|
53
|
+
|
|
54
|
+
Next.js only discovers middleware/proxy files in the parent directory of `app/`. A file at the wrong level is **silently ignored** — no error, just doesn't run.
|
|
55
|
+
|
|
56
|
+
## Step 5: Version Detection (Decision Tree)
|
|
39
57
|
|
|
40
58
|
Read Next.js version from `package.json`:
|
|
41
59
|
|
|
42
60
|
```
|
|
43
61
|
Next.js version?
|
|
44
62
|
|
|
|
45
|
-
+-- 16+ --> Create proxy.ts
|
|
63
|
+
+-- 16+ --> Create {APP_DIR}/proxy.ts
|
|
46
64
|
|
|
|
47
|
-
+-- 15 --> Create middleware.ts (cookies() is async
|
|
65
|
+
+-- 15 --> Create {APP_DIR}/middleware.ts (cookies() is async)
|
|
48
66
|
|
|
|
49
|
-
+-- 13-14 --> Create middleware.ts (cookies() is sync)
|
|
67
|
+
+-- 13-14 --> Create {APP_DIR}/middleware.ts (cookies() is sync)
|
|
50
68
|
```
|
|
51
69
|
|
|
52
|
-
**
|
|
70
|
+
**Next.js 16+ proxy.ts:** `proxy.ts` is the preferred convention. `middleware.ts` still works but shows a deprecation warning. Next.js 16 throws **error E900** if both files exist at the same level.
|
|
53
71
|
|
|
54
72
|
**Next.js 15+ async note:** All route handlers and middleware accessing cookies must be async and properly await cookie operations. This is a breaking change from Next.js 14.
|
|
55
73
|
|
|
@@ -95,14 +113,14 @@ export default async function middleware(request: NextRequest) {
|
|
|
95
113
|
|
|
96
114
|
**Critical:** Always return via `handleAuthkitHeaders()` to ensure `withAuth()` works in pages.
|
|
97
115
|
|
|
98
|
-
## Step
|
|
116
|
+
## Step 6: Create Callback Route
|
|
99
117
|
|
|
100
118
|
Parse `NEXT_PUBLIC_WORKOS_REDIRECT_URI` to determine route path:
|
|
101
119
|
|
|
102
120
|
```
|
|
103
|
-
URI path --> Route location
|
|
104
|
-
/auth/callback --> app/auth/callback/route.ts
|
|
105
|
-
/callback --> app/callback/route.ts
|
|
121
|
+
URI path --> Route location (use APP_DIR from Step 4)
|
|
122
|
+
/auth/callback --> {APP_DIR}/app/auth/callback/route.ts
|
|
123
|
+
/callback --> {APP_DIR}/app/callback/route.ts
|
|
106
124
|
```
|
|
107
125
|
|
|
108
126
|
Use `handleAuth()` from SDK. Do not write custom OAuth logic.
|
|
@@ -118,7 +136,7 @@ export const GET = handleAuth();
|
|
|
118
136
|
|
|
119
137
|
Check README for exact usage. If build fails with "cookies outside request scope", the handler is likely missing async/await.
|
|
120
138
|
|
|
121
|
-
## Step
|
|
139
|
+
## Step 7: Provider Setup (REQUIRED)
|
|
122
140
|
|
|
123
141
|
**CRITICAL:** You MUST wrap the app in `AuthKitProvider` in `app/layout.tsx`.
|
|
124
142
|
|
|
@@ -147,7 +165,7 @@ Check README for exact import path - it may be a subpath export like `@workos-in
|
|
|
147
165
|
|
|
148
166
|
**Do NOT skip this step** even if using server-side auth patterns elsewhere.
|
|
149
167
|
|
|
150
|
-
## Step
|
|
168
|
+
## Step 8: UI Integration
|
|
151
169
|
|
|
152
170
|
Add auth UI to `app/page.tsx` using SDK functions. See README for `getUser`, `getSignInUrl`, `signOut` usage.
|
|
153
171
|
|
|
@@ -191,6 +209,18 @@ This error causes OAuth codes to expire ("invalid_grant"), so fix the handler fi
|
|
|
191
209
|
- Check: File at project root or `src/`, not inside `app/`
|
|
192
210
|
- Check: Filename matches Next.js version (proxy.ts for 16+, middleware.ts for 13-15)
|
|
193
211
|
|
|
212
|
+
### "Both middleware file and proxy file are detected" (Next.js 16+)
|
|
213
|
+
|
|
214
|
+
- Next.js 16 throws error E900 if both `middleware.ts` and `proxy.ts` exist
|
|
215
|
+
- Delete `middleware.ts` and use only `proxy.ts`
|
|
216
|
+
- If `middleware.ts` has custom logic, migrate it into `proxy.ts`
|
|
217
|
+
|
|
218
|
+
### "withAuth route not covered by middleware" but middleware/proxy file exists
|
|
219
|
+
|
|
220
|
+
- **Most common cause:** File is at the wrong level. Next.js only discovers middleware/proxy files in the parent directory of `app/`. For `src/app/` projects, the file must be in `src/`, not at the project root.
|
|
221
|
+
- Check: Is `app/` at `src/app/`? Then middleware/proxy must be at `src/middleware.ts` or `src/proxy.ts`
|
|
222
|
+
- Check: Matcher config must include the route path being accessed
|
|
223
|
+
|
|
194
224
|
### "Cannot use getUser in client component"
|
|
195
225
|
|
|
196
226
|
- Check: Component has no `'use client'` directive, or
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: workos-authkit-sveltekit
|
|
3
|
+
description: Integrate WorkOS AuthKit with SvelteKit. Server-side authentication with hooks and file-based routing.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# WorkOS AuthKit for SvelteKit
|
|
7
|
+
|
|
8
|
+
## Step 1: Fetch SDK Documentation (BLOCKING)
|
|
9
|
+
|
|
10
|
+
**STOP. Do not proceed until complete.**
|
|
11
|
+
|
|
12
|
+
WebFetch: `https://github.com/workos/authkit-sveltekit/blob/main/README.md`
|
|
13
|
+
|
|
14
|
+
The README is the source of truth. If this skill conflicts with README, follow README.
|
|
15
|
+
|
|
16
|
+
## Step 2: Pre-Flight Validation
|
|
17
|
+
|
|
18
|
+
### Project Structure
|
|
19
|
+
|
|
20
|
+
- Confirm `svelte.config.js` (or `svelte.config.ts`) exists
|
|
21
|
+
- Confirm `package.json` contains `@sveltejs/kit` dependency
|
|
22
|
+
- Confirm `src/routes/` directory exists
|
|
23
|
+
|
|
24
|
+
### Environment Variables
|
|
25
|
+
|
|
26
|
+
Check `.env` or `.env.local` for:
|
|
27
|
+
|
|
28
|
+
- `WORKOS_API_KEY` - starts with `sk_`
|
|
29
|
+
- `WORKOS_CLIENT_ID` - starts with `client_`
|
|
30
|
+
- `WORKOS_REDIRECT_URI` - valid callback URL
|
|
31
|
+
- `WORKOS_COOKIE_PASSWORD` - 32+ characters
|
|
32
|
+
|
|
33
|
+
SvelteKit uses `$env/static/private` and `$env/dynamic/private` natively. The agent should write env vars to `.env` (SvelteKit's default) or `.env.local`.
|
|
34
|
+
|
|
35
|
+
## Step 3: Install SDK
|
|
36
|
+
|
|
37
|
+
Detect package manager, install SDK package from README.
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
pnpm-lock.yaml? → pnpm add @workos-inc/authkit-sveltekit
|
|
41
|
+
yarn.lock? → yarn add @workos-inc/authkit-sveltekit
|
|
42
|
+
bun.lockb? → bun add @workos-inc/authkit-sveltekit
|
|
43
|
+
else → npm install @workos-inc/authkit-sveltekit
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Verify:** SDK package exists in node_modules before continuing.
|
|
47
|
+
|
|
48
|
+
## Step 4: Configure Server Hooks
|
|
49
|
+
|
|
50
|
+
SvelteKit uses `src/hooks.server.ts` for server-side middleware. This is where the AuthKit handler is registered.
|
|
51
|
+
|
|
52
|
+
Create or update `src/hooks.server.ts` with the authkit handle function from the README.
|
|
53
|
+
|
|
54
|
+
### Existing Hooks (IMPORTANT)
|
|
55
|
+
|
|
56
|
+
If `src/hooks.server.ts` already exists with custom logic, use SvelteKit's `sequence()` helper to compose hooks:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { sequence } from '@sveltejs/kit/hooks';
|
|
60
|
+
import { authkitHandle } from '@workos-inc/authkit-sveltekit'; // Check README for exact export
|
|
61
|
+
|
|
62
|
+
export const handle = sequence(authkitHandle, yourExistingHandle);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Check README for the exact export name and usage pattern.
|
|
66
|
+
|
|
67
|
+
## Step 5: Create Callback Route
|
|
68
|
+
|
|
69
|
+
Parse `WORKOS_REDIRECT_URI` to determine route path:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
URI path --> Route location
|
|
73
|
+
/callback --> src/routes/callback/+server.ts
|
|
74
|
+
/auth/callback --> src/routes/auth/callback/+server.ts
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Use the SDK's callback handler from the README. Do not write custom OAuth logic.
|
|
78
|
+
|
|
79
|
+
**Critical:** SvelteKit uses `+server.ts` for API routes, not `+page.server.ts`.
|
|
80
|
+
|
|
81
|
+
## Step 6: Layout Setup
|
|
82
|
+
|
|
83
|
+
Update `src/routes/+layout.server.ts` to load the auth session and pass it to all pages.
|
|
84
|
+
|
|
85
|
+
Check README for the exact pattern — typically a `load` function that returns the user session from locals.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
// src/routes/+layout.server.ts
|
|
89
|
+
import type { LayoutServerLoad } from './$types';
|
|
90
|
+
|
|
91
|
+
export const load: LayoutServerLoad = async (event) => {
|
|
92
|
+
// Check README for exact API — session is typically on event.locals
|
|
93
|
+
return {
|
|
94
|
+
user: event.locals.user, // or similar from README
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Step 7: UI Integration
|
|
100
|
+
|
|
101
|
+
Add auth UI to `src/routes/+page.svelte` using the session data from the layout.
|
|
102
|
+
|
|
103
|
+
- Show user info when authenticated
|
|
104
|
+
- Show sign-in link/button when not authenticated
|
|
105
|
+
- Add sign-out functionality
|
|
106
|
+
|
|
107
|
+
Check README for sign-in URL generation and sign-out patterns.
|
|
108
|
+
|
|
109
|
+
## Verification Checklist (ALL MUST PASS)
|
|
110
|
+
|
|
111
|
+
Run these commands to confirm integration. **Do not mark complete until all pass:**
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# 1. Check hooks.server.ts exists and has authkit
|
|
115
|
+
grep -i "workos\|authkit" src/hooks.server.ts || echo "FAIL: authkit missing from hooks.server.ts"
|
|
116
|
+
|
|
117
|
+
# 2. Check callback route exists
|
|
118
|
+
find src/routes -name "+server.ts" -path "*/callback/*"
|
|
119
|
+
|
|
120
|
+
# 3. Check layout loads auth session
|
|
121
|
+
grep -i "user\|auth\|session" src/routes/+layout.server.ts || echo "FAIL: auth session missing from layout"
|
|
122
|
+
|
|
123
|
+
# 4. Build succeeds
|
|
124
|
+
pnpm build || npm run build
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Error Recovery
|
|
128
|
+
|
|
129
|
+
### "Cannot find module '@workos-inc/authkit-sveltekit'"
|
|
130
|
+
|
|
131
|
+
- Check: SDK installed before writing imports
|
|
132
|
+
- Check: SDK package directory exists in node_modules
|
|
133
|
+
- Re-run install if missing
|
|
134
|
+
|
|
135
|
+
### hooks.server.ts not taking effect
|
|
136
|
+
|
|
137
|
+
- Check: File is at `src/hooks.server.ts`, not `src/hooks.ts` or elsewhere
|
|
138
|
+
- Check: Named export is `handle` (SvelteKit requirement)
|
|
139
|
+
- Check: If using `sequence()`, all handles are properly composed
|
|
140
|
+
|
|
141
|
+
### Callback route not found (404)
|
|
142
|
+
|
|
143
|
+
- Check: File uses `+server.ts` (not `+page.server.ts`)
|
|
144
|
+
- Check: Route path matches `WORKOS_REDIRECT_URI` path exactly
|
|
145
|
+
- Check: Exports `GET` handler (SvelteKit convention)
|
|
146
|
+
|
|
147
|
+
### "locals" type errors
|
|
148
|
+
|
|
149
|
+
- Check: App.Locals interface is augmented in `src/app.d.ts`
|
|
150
|
+
- Check README for TypeScript setup instructions
|
|
151
|
+
|
|
152
|
+
### Cookie password error
|
|
153
|
+
|
|
154
|
+
- Verify `WORKOS_COOKIE_PASSWORD` is 32+ characters
|
|
155
|
+
- Generate new: `openssl rand -base64 32`
|
|
156
|
+
|
|
157
|
+
### Auth state not available in pages
|
|
158
|
+
|
|
159
|
+
- Check: `+layout.server.ts` load function returns user data
|
|
160
|
+
- Check: Pages access data via `export let data` (Svelte 4) or `$page.data` (Svelte 5)
|
|
@@ -0,0 +1,163 @@
|
|
|
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
|