kinde-testkit 0.6.0 → 0.7.0
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 +19 -0
- package/README.md +89 -3
- package/dist/chunk-2QJ7DTNL.js +72 -0
- package/dist/chunk-2QJ7DTNL.js.map +1 -0
- package/dist/chunk-33AHOLUN.js +183 -0
- package/dist/chunk-33AHOLUN.js.map +1 -0
- package/dist/chunk-JTAB2S44.js +3697 -0
- package/dist/chunk-JTAB2S44.js.map +1 -0
- package/dist/cli.js +50 -3561
- package/dist/cli.js.map +1 -0
- package/dist/cypress.cjs +286 -17
- package/dist/cypress.d.cts +2 -96
- package/dist/cypress.d.ts +3 -96
- package/dist/cypress.js +2 -3303
- package/dist/cypress.js.map +1 -1
- package/dist/handle-E_BhdHx8.d.ts +33 -0
- package/dist/handle-estfqypp.d.cts +32 -0
- package/dist/index.cjs +286 -17
- package/dist/index.d.cts +7 -607
- package/dist/index.d.ts +8 -607
- package/dist/index.js +51 -3577
- package/dist/index.js.map +1 -1
- package/dist/jest.cjs +286 -17
- package/dist/jest.d.cts +5 -555
- package/dist/jest.d.ts +6 -555
- package/dist/jest.js +4 -3373
- package/dist/jest.js.map +1 -1
- package/dist/playwright.d.ts +2 -54
- package/dist/server-B9fBcnyQ.d.ts +194 -0
- package/dist/server-CTBJXMac.d.cts +588 -0
- package/dist/vitest.d.ts +6 -555
- package/dist/vitest.js +5 -3376
- package/dist/vitest.js.map +1 -1
- package/dist/webhooks-DJyCsbdF.d.ts +397 -0
- package/package.json +3 -2
- package/dist/cypress-support.d.ts +0 -98
- package/dist/cypress.cjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/jest.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
Found by running the new contract tests against a real Kinde business.
|
|
6
|
+
|
|
7
|
+
- Add the device authorization flow: `POST /oauth2/device/auth`, a `/device` page where the user enters the code and signs in, polling with `authorization_pending`, `slow_down`, `access_denied` and `expired_token`, and `POST /testkit/device` to approve or deny without a browser. Change timing with the `device` option.
|
|
8
|
+
- Add token introspection at `/oauth2/introspect` and dynamic client registration at `/oauth2/register`, with the same errors Kinde returns.
|
|
9
|
+
- A seeded application that lists `audience` may now only request those audiences, and gets Kinde's "has not been whitelisted" error for any other.
|
|
10
|
+
- The discovery document now lists the same endpoints and grant types as a Kinde business.
|
|
11
|
+
- Coverage adds a device sign-in item.
|
|
12
|
+
- The contract tests also compare introspection and registration errors, and explain how to authorize the Management API when Kinde refuses the M2M token.
|
|
13
|
+
|
|
14
|
+
## 0.6.1
|
|
15
|
+
|
|
16
|
+
- Cut the package from 923 kB to 321 kB. The ESM entry points now share one copy of the issuer instead of each bundling its own.
|
|
17
|
+
- With `--json`, CLI errors are one JSON object with `code`, `message` and `details`, so scripts and coding agents can read why a command failed. Error details no longer print twice.
|
|
18
|
+
- Add contract tests that compare discovery, JWKS, M2M token claims and Management API responses with a real Kinde business. Run them with `npm run test:contract`.
|
|
19
|
+
- Add a contents list and a section for coding agents to the README.
|
|
20
|
+
- Fix the Next.js example's Cypress outage test, which failed because the first visit landed on the testkit.
|
|
21
|
+
|
|
3
22
|
## 0.6.0
|
|
4
23
|
|
|
5
24
|
- Add `kinde-testkit/jest` with the same `useKindeTestkit()` and `kindeTest()` as the Vitest helper, for CommonJS and ESM test files.
|
package/README.md
CHANGED
|
@@ -11,6 +11,34 @@ There are two ways to use it:
|
|
|
11
11
|
|
|
12
12
|
It also issues machine-to-machine tokens, answers the Management API and Account API calls your app makes, sends signed webhooks, and makes Kinde's endpoints fail or slow down on demand. A local dashboard shows what the testkit issued and answered, a coverage report shows which authentication cases your tests reached, and a `doctor` command checks your app's Kinde settings before a test run. It runs with Vitest, Jest, Playwright and Cypress, from the command line, or in Docker.
|
|
13
13
|
|
|
14
|
+
## Contents
|
|
15
|
+
|
|
16
|
+
- [Why it exists](#why-it-exists)
|
|
17
|
+
- [How it works](#how-it-works)
|
|
18
|
+
- [Install](#install)
|
|
19
|
+
- [Quick start with Vitest](#quick-start-with-vitest)
|
|
20
|
+
- [Browser tests with Playwright](#browser-tests-with-playwright)
|
|
21
|
+
- [Browser tests with Cypress](#browser-tests-with-cypress)
|
|
22
|
+
- [Machine-to-machine tokens](#machine-to-machine-tokens)
|
|
23
|
+
- [Device sign-in, introspection and client registration](#device-sign-in-introspection-and-client-registration)
|
|
24
|
+
- [Webhooks](#webhooks)
|
|
25
|
+
- [Management API and Account API](#management-api-and-account-api)
|
|
26
|
+
- [Testing outages](#testing-outages)
|
|
27
|
+
- [Check your setup](#check-your-setup)
|
|
28
|
+
- [With Kinde's SDKs](#with-kindes-sdks)
|
|
29
|
+
- [Use with a coding agent](#use-with-a-coding-agent)
|
|
30
|
+
- [Checked against real Kinde](#checked-against-real-kinde)
|
|
31
|
+
- [Run the issuer from the command line](#run-the-issuer-from-the-command-line)
|
|
32
|
+
- [Dashboard](#dashboard)
|
|
33
|
+
- [Authentication coverage](#authentication-coverage)
|
|
34
|
+
- [Docker](#docker)
|
|
35
|
+
- [Invalid tokens](#invalid-tokens)
|
|
36
|
+
- [API](#api)
|
|
37
|
+
- [Endpoints](#endpoints)
|
|
38
|
+
- [Token shape](#token-shape)
|
|
39
|
+
- [What this release covers](#what-this-release-covers)
|
|
40
|
+
- [Safety](#safety)
|
|
41
|
+
|
|
14
42
|
## Why it exists
|
|
15
43
|
|
|
16
44
|
Kinde's testing guides start with a test environment, a test user with a password, and a client ID and secret in `.env`. Every test then goes through a real sign-in. That works for a few smoke tests. It gets slow and hard to run in CI once you want to test what your app does with each kind of user, such as:
|
|
@@ -240,7 +268,7 @@ Seed the apps your services use:
|
|
|
240
268
|
}
|
|
241
269
|
```
|
|
242
270
|
|
|
243
|
-
A seeded app with a `clientSecret` must send that secret. A seeded app with `scopes` is granted only the requested scopes it has, so `scope` holds what was granted and `scp` holds what was asked for, as in Kinde. A client ID that is not seeded gets a token with whatever it asks for.
|
|
271
|
+
A seeded app with a `clientSecret` must send that secret. A seeded app with `scopes` is granted only the requested scopes it has, so `scope` holds what was granted and `scp` holds what was asked for, as in Kinde. A seeded app with `audience` may only ask for those audiences. Any other answers `400 invalid_request` with Kinde's message, "Requested audience ... has not been whitelisted by the OAuth 2.0 Client", the error you get in Kinde when an API is not authorized for the app. A client ID that is not seeded gets a token with whatever it asks for.
|
|
244
272
|
|
|
245
273
|
Your service fetches a token the same way it does from Kinde:
|
|
246
274
|
|
|
@@ -252,6 +280,33 @@ curl -s -X POST http://localhost:4400/oauth2/token \
|
|
|
252
280
|
|
|
253
281
|
In tests, mint one directly with `testkit.m2mToken({ clientId, organizationCode, scopes, audience })`, or run `kinde-testkit token --m2m --client-id acme_agent --scope read:users`. M2M tokens take the same `invalid` kinds as user tokens. `principalFromClaims()` reads them as `{ type: "machine", subject: <client ID> }`.
|
|
254
282
|
|
|
283
|
+
## Device sign-in, introspection and client registration
|
|
284
|
+
|
|
285
|
+
CLIs, TV apps and agents that cannot open a browser sign in with the device authorization flow. The device asks the testkit for a code, shows it to the user, and polls `/oauth2/token` until the user approves:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
curl -s -X POST http://localhost:4400/oauth2/device/auth -d client_id=my_cli -d audience=https://api.example.test
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
```json
|
|
292
|
+
{ "device_code": "kinde_dc_...", "user_code": "CSLDFDUU", "verification_uri": "http://localhost:4400/device",
|
|
293
|
+
"verification_uri_complete": "http://localhost:4400/device?user_code=CSLDFDUU", "expires_in": 600, "interval": 5 }
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
The user opens `verification_uri`, enters the code and signs in on the normal sign-in page. Until then, polling answers `authorization_pending`, polling faster than `interval` answers `slow_down`, a denied device gets `access_denied` and an old code gets `expired_token`, as in Kinde. Tests can approve or deny without a browser:
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
curl -X POST http://localhost:4400/testkit/device -H 'content-type: application/json' \
|
|
300
|
+
-d '{"user_code":"CSLDFDUU","user":"admin@example.test","organization":"org_acme"}'
|
|
301
|
+
# or {"user_code":"CSLDFDUU","action":"deny"}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Kinde polls every 5 seconds. Set `device: { intervalSeconds: 0 }` in `useKindeTestkit()` or `startKindeTestkit()` so tests do not wait. `expiresInSeconds` changes the code lifetime. Kinde's response also has a `qr_code` image, which the testkit leaves out.
|
|
305
|
+
|
|
306
|
+
`POST /oauth2/introspect` tells a resource server whether a token is active. Like Kinde, it needs a Bearer token, which must be different from the token being checked, and answers `{ active, aud, client_id, exp, iat }` or `{ active: false }`.
|
|
307
|
+
|
|
308
|
+
`POST /oauth2/register` is OAuth dynamic client registration, which Kinde offers for MCP connectors. Send `redirect_uris` and an optional `client_name` as JSON, and the testkit returns a new public `client_id`. A request with no valid redirect URIs gets Kinde's `invalid_redirect_uri` error. Kinde only accepts the redirect URIs of approved MCP clients, and it does not publish that list, so the testkit accepts any `http` or `https` redirect URI.
|
|
309
|
+
|
|
255
310
|
## Webhooks
|
|
256
311
|
|
|
257
312
|
Kinde sends webhooks as a signed JWT with `Content-Type: application/jwt` and a `webhook-id` header that stays the same across retries. Your endpoint checks the signature with `decodeWebhook()` from `@kinde/webhooks`, which fetches keys from your issuer. kinde-testkit sends webhooks the same way, signed with its own key, so the same handler code works in tests when `KINDE_ISSUER_URL` points at the testkit.
|
|
@@ -424,6 +479,31 @@ KINDE_ISSUER_URL=http://localhost:4400
|
|
|
424
479
|
|
|
425
480
|
The SDK accepts a plain `http://localhost` issuer. Its login, callback, refresh, logout and session-ending routes all work against the testkit. Its `validateToken` accepts kinde-testkit tokens and rejects the wrong-issuer, tampered, unknown-key and unsigned kinds. It does not reject expired tokens, because the SDK handles expiry by refreshing the session.
|
|
426
481
|
|
|
482
|
+
## Use with a coding agent
|
|
483
|
+
|
|
484
|
+
Every command takes `--json` and exits with code 1 when something fails. With `--json`, errors are one JSON object, `{ "error": { "code", "message", "details" } }`, so an agent can read the result and the reason without parsing text. A typical loop:
|
|
485
|
+
|
|
486
|
+
```bash
|
|
487
|
+
npx kinde-testkit start --json & # prints the issuer URL and seed counts as JSON
|
|
488
|
+
npx kinde-testkit doctor --json # checks the app's .env against the issuer
|
|
489
|
+
npx kinde-testkit token --user admin@example.test --json
|
|
490
|
+
npx kinde-testkit inspect "$TOKEN" --json # explains why a token was rejected
|
|
491
|
+
npx kinde-testkit coverage --url http://localhost:4400 --json # lists the auth cases not tested yet
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
Point the agent at three facts: the app's `KINDE_ISSUER_URL` must be the testkit's URL during tests, users and organizations come from `kinde-testkit.json` or `kinde-testkit.yaml`, and `kinde-testkit coverage` names the missing cases with the one-line change that tests each of them.
|
|
495
|
+
|
|
496
|
+
## Checked against real Kinde
|
|
497
|
+
|
|
498
|
+
`test/contract` sends the same requests to a real Kinde business and to the testkit and fails on any field Kinde returns that the testkit does not: discovery endpoints, JWKS keys, M2M token claims, the Management API's error for a missing token, and the fields of users, organizations, roles and permissions. It only reads. Run it with an M2M app that has the `read:users`, `read:organizations`, `read:roles` and `read:permissions` scopes in a test business:
|
|
499
|
+
|
|
500
|
+
```bash
|
|
501
|
+
KINDE_CONTRACT_DOMAIN=https://<your-business>.kinde.com \
|
|
502
|
+
KINDE_CONTRACT_CLIENT_ID=<client ID> \
|
|
503
|
+
KINDE_CONTRACT_CLIENT_SECRET=<client secret> \
|
|
504
|
+
npm run test:contract
|
|
505
|
+
```
|
|
506
|
+
|
|
427
507
|
## Run the issuer from the command line
|
|
428
508
|
|
|
429
509
|
```bash
|
|
@@ -526,13 +606,13 @@ Identity 6/6
|
|
|
526
606
|
Organizations 4/5
|
|
527
607
|
Permissions 5/5
|
|
528
608
|
Token validation 3/8
|
|
529
|
-
Sessions 4/
|
|
609
|
+
Sessions 4/6
|
|
530
610
|
Machine-to-machine 0/4
|
|
531
611
|
Kinde APIs 2/4
|
|
532
612
|
Webhooks 5/5
|
|
533
613
|
Outages 2/4
|
|
534
614
|
|
|
535
|
-
Overall: 31/
|
|
615
|
+
Overall: 31/47
|
|
536
616
|
|
|
537
617
|
Not covered:
|
|
538
618
|
Organizations: Organization claim missing. Mint a token with invalid: "missing-organization".
|
|
@@ -654,6 +734,10 @@ From `kinde-testkit/playwright`: `test` and `expect` with the `kinde` fixture, t
|
|
|
654
734
|
| `POST /oauth2/token` | `authorization_code`, `refresh_token` and `client_credentials` grants. Client credentials in the body or with HTTP Basic. Refresh tokens rotate on every use |
|
|
655
735
|
| `GET /oauth2/v2/user_profile` | Profile for the Bearer token's user |
|
|
656
736
|
| `POST /oauth2/revoke` | Revokes a refresh token |
|
|
737
|
+
| `POST /oauth2/device/auth`, `GET /device` | Device authorization flow: the device code request and the page where the user enters the code |
|
|
738
|
+
| `POST /oauth2/introspect` | Token introspection. Needs a Bearer token |
|
|
739
|
+
| `POST /oauth2/register` | Dynamic client registration for MCP connectors |
|
|
740
|
+
| `POST /testkit/device` | Approves or denies a pending device code without a browser |
|
|
657
741
|
| `GET /logout?redirect=<url>` | Signs out and redirects |
|
|
658
742
|
| `/api/v1/...` | Management API: users, organizations, members, roles and permissions |
|
|
659
743
|
| `GET /account_api/v1/...` | Account API: permissions, roles, feature flags, properties and entitlements for the token's user |
|
|
@@ -709,6 +793,8 @@ ID tokens carry `amr`, `aud` (the client ID), `auth_time`, `email`, `email_verif
|
|
|
709
793
|
| Switching the active organization | Implemented through `org_code` or the organization picker |
|
|
710
794
|
| Authorization code flow with sign-in page, PKCE and `state` | Implemented |
|
|
711
795
|
| Refresh tokens with rotation, revocation, logout and user profile | Implemented |
|
|
796
|
+
| Device authorization flow, token introspection and dynamic client registration | Implemented. Error responses checked against a real Kinde business. The device response has no `qr_code` |
|
|
797
|
+
| Audience allow-list for seeded M2M apps | Implemented, with Kinde's error message |
|
|
712
798
|
| Vitest and Jest helpers, Playwright fixture, Cypress commands | Implemented. Jest runs in the test suite. Cypress's sign-in steps are tested against the Next.js SDK |
|
|
713
799
|
| Accepted by `@kinde/jwt-validator` and the Next.js SDK's `validateToken` | Tested |
|
|
714
800
|
| Sign-in, organization switching and sign-out through `@kinde-oss/kinde-auth-nextjs` | Tested in Chrome with Playwright |
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDefaultTestkit,
|
|
3
|
+
startKindeTestkit
|
|
4
|
+
} from "./chunk-JTAB2S44.js";
|
|
5
|
+
|
|
6
|
+
// src/handle.ts
|
|
7
|
+
async function kindeTest(options) {
|
|
8
|
+
const testkit = options.testkit ?? await getDefaultTestkit();
|
|
9
|
+
const token = await testkit.tokenFor(options.scenario, options.token);
|
|
10
|
+
const headers = token ? { authorization: `Bearer ${token}` } : {};
|
|
11
|
+
return {
|
|
12
|
+
token,
|
|
13
|
+
headers,
|
|
14
|
+
principal: testkit.principalFor(options.scenario),
|
|
15
|
+
request: { headers }
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function createKindeTestkitHandle(hooks, options, name) {
|
|
19
|
+
let running = null;
|
|
20
|
+
hooks.beforeAll(async () => {
|
|
21
|
+
running = await startKindeTestkit({ port: 0, ...options });
|
|
22
|
+
});
|
|
23
|
+
hooks.afterAll(async () => {
|
|
24
|
+
await running?.close();
|
|
25
|
+
running = null;
|
|
26
|
+
});
|
|
27
|
+
const current = () => {
|
|
28
|
+
if (!running) throw new Error(`${name}() is only ready inside tests and hooks, after beforeAll runs.`);
|
|
29
|
+
return running;
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
get url() {
|
|
33
|
+
return current().url;
|
|
34
|
+
},
|
|
35
|
+
get issuer() {
|
|
36
|
+
return current().issuer;
|
|
37
|
+
},
|
|
38
|
+
get jwksUri() {
|
|
39
|
+
return current().jwksUri;
|
|
40
|
+
},
|
|
41
|
+
get testkit() {
|
|
42
|
+
return current().testkit;
|
|
43
|
+
},
|
|
44
|
+
get failures() {
|
|
45
|
+
return current().failures;
|
|
46
|
+
},
|
|
47
|
+
get webhooks() {
|
|
48
|
+
return current().webhooks;
|
|
49
|
+
},
|
|
50
|
+
get directory() {
|
|
51
|
+
return current().directory;
|
|
52
|
+
},
|
|
53
|
+
get coverage() {
|
|
54
|
+
return current().coverage;
|
|
55
|
+
},
|
|
56
|
+
get activity() {
|
|
57
|
+
return current().activity;
|
|
58
|
+
},
|
|
59
|
+
get certificatePath() {
|
|
60
|
+
return current().certificatePath;
|
|
61
|
+
},
|
|
62
|
+
auth: (scenario, token) => kindeTest({ scenario, testkit: current().testkit, token }),
|
|
63
|
+
loadSeed: (seed) => current().loadSeed(seed),
|
|
64
|
+
reset: () => current().reset()
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
kindeTest,
|
|
70
|
+
createKindeTestkitHandle
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=chunk-2QJ7DTNL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/handle.ts"],"sourcesContent":["import { getDefaultTestkit, type KindeTestkit, type ScenarioTokenOverrides } from \"./testkit.js\";\nimport { startKindeTestkit, type RunningKindeTestkit, type StartKindeTestkitOptions } from \"./server.js\";\nimport type { ActivityLog } from \"./activity.js\";\nimport type { CoverageRecorder } from \"./coverage.js\";\nimport type { Directory } from \"./directory.js\";\nimport type { FailureInjector } from \"./failures.js\";\nimport type { TestkitSeed } from \"./seed.js\";\nimport type { WebhookDispatcher } from \"./webhooks.js\";\nimport type { KindePrincipal, Scenario } from \"./types.js\";\n\nexport interface KindeTestAuth {\n token: string | null;\n headers: Record<string, string>;\n principal: KindePrincipal | null;\n request: { headers: Record<string, string> };\n}\n\nexport async function kindeTest(options: {\n scenario: Scenario;\n testkit?: KindeTestkit;\n token?: ScenarioTokenOverrides;\n}): Promise<KindeTestAuth> {\n const testkit = options.testkit ?? (await getDefaultTestkit());\n const token = await testkit.tokenFor(options.scenario, options.token);\n const headers: Record<string, string> = token ? { authorization: `Bearer ${token}` } : {};\n return {\n token,\n headers,\n principal: testkit.principalFor(options.scenario),\n request: { headers },\n };\n}\n\nexport interface KindeTestkitHandle {\n readonly url: string;\n readonly issuer: string;\n readonly jwksUri: string;\n readonly testkit: KindeTestkit;\n readonly failures: FailureInjector;\n readonly webhooks: WebhookDispatcher;\n readonly directory: Directory;\n readonly coverage: CoverageRecorder;\n readonly activity: ActivityLog;\n readonly certificatePath: string | null;\n auth(scenario: Scenario, token?: ScenarioTokenOverrides): Promise<KindeTestAuth>;\n loadSeed(seed: TestkitSeed): void;\n reset(): void;\n}\n\ntype Hook = (fn: () => Promise<void>, timeout?: number) => void;\n\n/** Starts a testkit before the tests in the file and stops it after them. Shared by the Vitest and Jest helpers. */\nexport function createKindeTestkitHandle(\n hooks: { beforeAll: Hook; afterAll: Hook },\n options: StartKindeTestkitOptions,\n name: string,\n): KindeTestkitHandle {\n let running: RunningKindeTestkit | null = null;\n\n hooks.beforeAll(async () => {\n running = await startKindeTestkit({ port: 0, ...options });\n });\n hooks.afterAll(async () => {\n await running?.close();\n running = null;\n });\n\n const current = (): RunningKindeTestkit => {\n if (!running) throw new Error(`${name}() is only ready inside tests and hooks, after beforeAll runs.`);\n return running;\n };\n\n return {\n get url() {\n return current().url;\n },\n get issuer() {\n return current().issuer;\n },\n get jwksUri() {\n return current().jwksUri;\n },\n get testkit() {\n return current().testkit;\n },\n get failures() {\n return current().failures;\n },\n get webhooks() {\n return current().webhooks;\n },\n get directory() {\n return current().directory;\n },\n get coverage() {\n return current().coverage;\n },\n get activity() {\n return current().activity;\n },\n get certificatePath() {\n return current().certificatePath;\n },\n auth: (scenario, token) => kindeTest({ scenario, testkit: current().testkit, token }),\n loadSeed: (seed) => current().loadSeed(seed),\n reset: () => current().reset(),\n };\n}\n"],"mappings":";;;;;;AAiBA,eAAsB,UAAU,SAIL;AACzB,QAAM,UAAU,QAAQ,WAA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nB;AAAA,IACA,MAAM,CAAC,UAAU,UAAU,UAAU,EAAE,UAAU,SAAS,QAAQ,EAAE,SAAS,MAAM,CAAC;AAAA,IACpF,UAAU,CAAC,SAAS,QAAQ,EAAE,SAAS,IAAI;AAAA,IAC3C,OAAO,MAAM,QAAQ,EAAE,MAAM;AAAA,EAC/B;AACF;","names":[]}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// src/inspect.ts
|
|
2
|
+
import { createRemoteJWKSet, decodeJwt, decodeProtectedHeader, jwtVerify } from "jose";
|
|
3
|
+
async function inspectToken(token, options = {}) {
|
|
4
|
+
const checks = [];
|
|
5
|
+
const trimmed = token.trim();
|
|
6
|
+
let header = null;
|
|
7
|
+
let payload = null;
|
|
8
|
+
if (trimmed.split(".").length !== 3) {
|
|
9
|
+
checks.push({ name: "Format", status: "fail", detail: "A JWT has three parts separated by dots." });
|
|
10
|
+
return { kind: "unknown", header, payload, checks };
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
header = decodeProtectedHeader(trimmed);
|
|
14
|
+
payload = decodeJwt(trimmed);
|
|
15
|
+
} catch {
|
|
16
|
+
checks.push({ name: "Format", status: "fail", detail: "The header or payload is not valid base64url JSON." });
|
|
17
|
+
return { kind: "unknown", header, payload, checks };
|
|
18
|
+
}
|
|
19
|
+
checks.push({ name: "Format", status: "pass", detail: "Three base64url parts with JSON header and payload." });
|
|
20
|
+
checks.push(
|
|
21
|
+
header.alg === "RS256" ? { name: "Algorithm", status: "pass", detail: "RS256, the algorithm Kinde signs with." } : { name: "Algorithm", status: "fail", detail: `${String(header.alg)} is not RS256. Kinde tokens are always RS256.` }
|
|
22
|
+
);
|
|
23
|
+
const signer = typeof header.kid === "string" && header.kid.startsWith("kinde-testkit") ? "kinde-testkit" : "another issuer";
|
|
24
|
+
checks.push({ name: "Key", status: "pass", detail: `kid ${String(header.kid ?? "missing")} (${signer}).` });
|
|
25
|
+
const now = options.now ?? Math.floor(Date.now() / 1e3);
|
|
26
|
+
if (typeof payload.exp !== "number") {
|
|
27
|
+
checks.push({ name: "Expiry", status: "fail", detail: "No exp claim." });
|
|
28
|
+
} else if (payload.exp <= now) {
|
|
29
|
+
checks.push({ name: "Expiry", status: "fail", detail: `Expired ${formatSpan(now - payload.exp)} ago.` });
|
|
30
|
+
} else {
|
|
31
|
+
checks.push({ name: "Expiry", status: "pass", detail: `Expires in ${formatSpan(payload.exp - now)}.` });
|
|
32
|
+
}
|
|
33
|
+
if (typeof payload.iat === "number" && payload.iat > now + 60) {
|
|
34
|
+
checks.push({ name: "Issued at", status: "fail", detail: `iat is ${formatSpan(payload.iat - now)} in the future.` });
|
|
35
|
+
}
|
|
36
|
+
if (options.issuerUrl) {
|
|
37
|
+
const issuer = options.issuerUrl.replace(/\/+$/, "");
|
|
38
|
+
if (payload.iss !== issuer) {
|
|
39
|
+
checks.push({ name: "Issuer", status: "fail", detail: `iss is ${String(payload.iss)}, not ${issuer}.` });
|
|
40
|
+
} else {
|
|
41
|
+
checks.push({ name: "Issuer", status: "pass", detail: `Issued by ${issuer}.` });
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await jwtVerify(trimmed, createRemoteJWKSet(new URL(`${issuer}/.well-known/jwks.json`)), { algorithms: ["RS256"] });
|
|
45
|
+
checks.push({ name: "Signature", status: "pass", detail: `Verified against ${issuer}/.well-known/jwks.json.` });
|
|
46
|
+
} catch (error) {
|
|
47
|
+
const code = error.code ?? "";
|
|
48
|
+
if (code === "ERR_JWT_EXPIRED" || code === "ERR_JWT_CLAIM_VALIDATION_FAILED") {
|
|
49
|
+
checks.push({ name: "Signature", status: "pass", detail: `Verified against ${issuer}/.well-known/jwks.json.` });
|
|
50
|
+
} else {
|
|
51
|
+
checks.push({ name: "Signature", status: "fail", detail: describeVerifyError(code, issuer) });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
checks.push({ name: "Signature", status: "warn", detail: "Not checked. Pass --url to verify against a running issuer." });
|
|
56
|
+
}
|
|
57
|
+
return { kind: kindOf(payload), header, payload, checks };
|
|
58
|
+
}
|
|
59
|
+
function kindOf(payload) {
|
|
60
|
+
if (Array.isArray(payload.gty) && payload.gty.includes("client_credentials")) return "m2m";
|
|
61
|
+
if ("email" in payload || "org_codes" in payload || "at_hash" in payload || "nonce" in payload) return "id";
|
|
62
|
+
if ("scp" in payload || "permissions" in payload || "org_code" in payload) return "access";
|
|
63
|
+
return "unknown";
|
|
64
|
+
}
|
|
65
|
+
function describeVerifyError(code, issuer) {
|
|
66
|
+
if (code === "ERR_JWKS_NO_MATCHING_KEY") return `No key in ${issuer}'s JWKS matches this token's kid.`;
|
|
67
|
+
if (code === "ERR_JWS_SIGNATURE_VERIFICATION_FAILED") return "The signature does not match the token. It was changed after signing.";
|
|
68
|
+
if (code === "ERR_JOSE_ALG_NOT_ALLOWED" || code === "ERR_JOSE_NOT_SUPPORTED") return "The token is not signed with RS256.";
|
|
69
|
+
if (code === "ERR_JWKS_TIMEOUT" || code === "ERR_JOSE_GENERIC") return `Could not fetch keys from ${issuer}.`;
|
|
70
|
+
return `Verification failed (${code || "unknown error"}).`;
|
|
71
|
+
}
|
|
72
|
+
function formatSpan(seconds) {
|
|
73
|
+
const s = Math.max(0, Math.round(seconds));
|
|
74
|
+
if (s < 60) return `${s}s`;
|
|
75
|
+
if (s < 3600) return `${Math.floor(s / 60)}m ${s % 60}s`;
|
|
76
|
+
if (s < 86400) return `${Math.floor(s / 3600)}h ${Math.floor(s % 3600 / 60)}m`;
|
|
77
|
+
return `${Math.floor(s / 86400)}d ${Math.floor(s % 86400 / 3600)}h`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/doctor.ts
|
|
81
|
+
var SECRET_FORMAT = /^[a-zA-Z0-9]{40,60}$/;
|
|
82
|
+
async function runDoctor(options) {
|
|
83
|
+
const url = options.url.replace(/\/+$/, "");
|
|
84
|
+
const checks = [];
|
|
85
|
+
let issuer = null;
|
|
86
|
+
try {
|
|
87
|
+
const health = await (await fetch(`${url}/testkit/health`)).json();
|
|
88
|
+
issuer = health.issuer ?? null;
|
|
89
|
+
checks.push({ name: "Issuer running", status: "pass", detail: `${url} answers, issuer ${issuer}.` });
|
|
90
|
+
} catch {
|
|
91
|
+
checks.push({ name: "Issuer running", status: "fail", detail: `Nothing answers at ${url}. Start it with "kinde-testkit start".` });
|
|
92
|
+
}
|
|
93
|
+
if (issuer) {
|
|
94
|
+
try {
|
|
95
|
+
const discovery = await (await fetch(`${url}/.well-known/openid-configuration`)).json();
|
|
96
|
+
checks.push(
|
|
97
|
+
discovery.issuer === issuer ? { name: "Discovery", status: "pass", detail: "The discovery document names the same issuer." } : { name: "Discovery", status: "fail", detail: `Discovery says ${String(discovery.issuer)}, health says ${issuer}.` }
|
|
98
|
+
);
|
|
99
|
+
} catch {
|
|
100
|
+
checks.push({ name: "Discovery", status: "fail", detail: "Could not read /.well-known/openid-configuration." });
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const jwks = await (await fetch(`${url}/.well-known/jwks.json`)).json();
|
|
104
|
+
const usable = (jwks.keys ?? []).filter((key) => key.kty === "RSA" && key.use === "sig");
|
|
105
|
+
checks.push(
|
|
106
|
+
usable.length > 0 ? { name: "JWKS", status: "pass", detail: `${usable.length} RS256 signing key at /.well-known/jwks.json.` } : { name: "JWKS", status: "fail", detail: "No RSA signing key at /.well-known/jwks.json." }
|
|
107
|
+
);
|
|
108
|
+
} catch {
|
|
109
|
+
checks.push({ name: "JWKS", status: "fail", detail: "Could not read /.well-known/jwks.json." });
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const users = await (await fetch(`${url}/testkit/users`)).json();
|
|
113
|
+
checks.push(
|
|
114
|
+
users.length > 0 ? { name: "Seed", status: "pass", detail: `${users.length} seeded ${users.length === 1 ? "user" : "users"}.` } : { name: "Seed", status: "warn", detail: "No seeded users. The sign-in page still accepts any email, but those users have no organization." }
|
|
115
|
+
);
|
|
116
|
+
} catch {
|
|
117
|
+
checks.push({ name: "Seed", status: "warn", detail: "Could not read /testkit/users." });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const env = options.env;
|
|
121
|
+
const configured = env.KINDE_ISSUER_URL?.trim().replace(/\/+$/, "");
|
|
122
|
+
if (!configured) {
|
|
123
|
+
checks.push({ name: "KINDE_ISSUER_URL", status: "fail", detail: "Not set. Set it to the testkit's issuer for test runs." });
|
|
124
|
+
} else if (/\.kinde\.com$/i.test(new URL(configured, "http://x").hostname)) {
|
|
125
|
+
checks.push({ name: "KINDE_ISSUER_URL", status: "fail", detail: `${configured} is a real Kinde domain. Tests would sign in against Kinde, not the testkit.` });
|
|
126
|
+
} else if (issuer && configured !== issuer) {
|
|
127
|
+
checks.push({ name: "KINDE_ISSUER_URL", status: "fail", detail: `${configured} does not match the testkit issuer ${issuer}. Token checks compare iss exactly.` });
|
|
128
|
+
} else {
|
|
129
|
+
checks.push({ name: "KINDE_ISSUER_URL", status: "pass", detail: `${configured}.` });
|
|
130
|
+
}
|
|
131
|
+
checks.push(
|
|
132
|
+
env.KINDE_CLIENT_ID ? { name: "KINDE_CLIENT_ID", status: "pass", detail: "Set. The testkit accepts any client ID." } : { name: "KINDE_CLIENT_ID", status: "fail", detail: "Not set. Kinde's SDKs refuse to start without it." }
|
|
133
|
+
);
|
|
134
|
+
const secret = env.KINDE_CLIENT_SECRET;
|
|
135
|
+
if (!secret) {
|
|
136
|
+
checks.push({ name: "KINDE_CLIENT_SECRET", status: "warn", detail: "Not set. Server-side SDKs, such as the Next.js SDK, need it." });
|
|
137
|
+
} else if (!SECRET_FORMAT.test(secret)) {
|
|
138
|
+
checks.push({ name: "KINDE_CLIENT_SECRET", status: "fail", detail: "The Next.js SDK only accepts 40 to 60 letters and digits." });
|
|
139
|
+
} else {
|
|
140
|
+
checks.push({ name: "KINDE_CLIENT_SECRET", status: "pass", detail: "Set, in the format Kinde's SDKs accept." });
|
|
141
|
+
}
|
|
142
|
+
if (issuer?.startsWith("https://")) {
|
|
143
|
+
checks.push(
|
|
144
|
+
env.NODE_EXTRA_CA_CERTS ? { name: "NODE_EXTRA_CA_CERTS", status: "pass", detail: `${env.NODE_EXTRA_CA_CERTS}.` } : {
|
|
145
|
+
name: "NODE_EXTRA_CA_CERTS",
|
|
146
|
+
status: "warn",
|
|
147
|
+
detail: "The testkit serves HTTPS with a local certificate. Start your app with NODE_EXTRA_CA_CERTS set to it, or Node will refuse the connection."
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
const site = env.KINDE_SITE_URL;
|
|
152
|
+
if (!site) {
|
|
153
|
+
checks.push({ name: "KINDE_SITE_URL", status: "warn", detail: "Not set. The Next.js SDK builds its callback URL from it." });
|
|
154
|
+
} else if (!/^https?:\/\//.test(site)) {
|
|
155
|
+
checks.push({ name: "KINDE_SITE_URL", status: "fail", detail: `${site} is not an http or https URL.` });
|
|
156
|
+
} else {
|
|
157
|
+
checks.push({ name: "KINDE_SITE_URL", status: "pass", detail: `${site}.` });
|
|
158
|
+
}
|
|
159
|
+
return { url, checks, ok: checks.every((check) => check.status !== "fail") };
|
|
160
|
+
}
|
|
161
|
+
function parseEnvFile(text) {
|
|
162
|
+
const values = {};
|
|
163
|
+
for (const line of text.split(/\r?\n/)) {
|
|
164
|
+
const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/.exec(line);
|
|
165
|
+
if (!match) continue;
|
|
166
|
+
let value = match[2];
|
|
167
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
168
|
+
value = value.slice(1, -1);
|
|
169
|
+
} else {
|
|
170
|
+
value = value.replace(/\s+#.*$/, "");
|
|
171
|
+
}
|
|
172
|
+
values[match[1]] = value;
|
|
173
|
+
}
|
|
174
|
+
return values;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export {
|
|
178
|
+
inspectToken,
|
|
179
|
+
formatSpan,
|
|
180
|
+
runDoctor,
|
|
181
|
+
parseEnvFile
|
|
182
|
+
};
|
|
183
|
+
//# sourceMappingURL=chunk-33AHOLUN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/inspect.ts","../src/doctor.ts"],"sourcesContent":["import { createRemoteJWKSet, decodeJwt, decodeProtectedHeader, jwtVerify, type JWTPayload, type ProtectedHeaderParameters } from \"jose\";\n\nexport type CheckStatus = \"pass\" | \"warn\" | \"fail\";\n\nexport interface Check {\n name: string;\n status: CheckStatus;\n detail: string;\n}\n\nexport interface TokenInspection {\n kind: \"access\" | \"id\" | \"m2m\" | \"unknown\";\n header: ProtectedHeaderParameters | null;\n payload: JWTPayload | null;\n checks: Check[];\n}\n\nexport async function inspectToken(\n token: string,\n options: { issuerUrl?: string; now?: number } = {},\n): Promise<TokenInspection> {\n const checks: Check[] = [];\n const trimmed = token.trim();\n let header: ProtectedHeaderParameters | null = null;\n let payload: JWTPayload | null = null;\n\n if (trimmed.split(\".\").length !== 3) {\n checks.push({ name: \"Format\", status: \"fail\", detail: \"A JWT has three parts separated by dots.\" });\n return { kind: \"unknown\", header, payload, checks };\n }\n try {\n header = decodeProtectedHeader(trimmed);\n payload = decodeJwt(trimmed);\n } catch {\n checks.push({ name: \"Format\", status: \"fail\", detail: \"The header or payload is not valid base64url JSON.\" });\n return { kind: \"unknown\", header, payload, checks };\n }\n checks.push({ name: \"Format\", status: \"pass\", detail: \"Three base64url parts with JSON header and payload.\" });\n\n checks.push(\n header.alg === \"RS256\"\n ? { name: \"Algorithm\", status: \"pass\", detail: \"RS256, the algorithm Kinde signs with.\" }\n : { name: \"Algorithm\", status: \"fail\", detail: `${String(header.alg)} is not RS256. Kinde tokens are always RS256.` },\n );\n\n const signer = typeof header.kid === \"string\" && header.kid.startsWith(\"kinde-testkit\") ? \"kinde-testkit\" : \"another issuer\";\n checks.push({ name: \"Key\", status: \"pass\", detail: `kid ${String(header.kid ?? \"missing\")} (${signer}).` });\n\n const now = options.now ?? Math.floor(Date.now() / 1000);\n if (typeof payload.exp !== \"number\") {\n checks.push({ name: \"Expiry\", status: \"fail\", detail: \"No exp claim.\" });\n } else if (payload.exp <= now) {\n checks.push({ name: \"Expiry\", status: \"fail\", detail: `Expired ${formatSpan(now - payload.exp)} ago.` });\n } else {\n checks.push({ name: \"Expiry\", status: \"pass\", detail: `Expires in ${formatSpan(payload.exp - now)}.` });\n }\n if (typeof payload.iat === \"number\" && payload.iat > now + 60) {\n checks.push({ name: \"Issued at\", status: \"fail\", detail: `iat is ${formatSpan(payload.iat - now)} in the future.` });\n }\n\n if (options.issuerUrl) {\n const issuer = options.issuerUrl.replace(/\\/+$/, \"\");\n if (payload.iss !== issuer) {\n checks.push({ name: \"Issuer\", status: \"fail\", detail: `iss is ${String(payload.iss)}, not ${issuer}.` });\n } else {\n checks.push({ name: \"Issuer\", status: \"pass\", detail: `Issued by ${issuer}.` });\n }\n try {\n await jwtVerify(trimmed, createRemoteJWKSet(new URL(`${issuer}/.well-known/jwks.json`)), { algorithms: [\"RS256\"] });\n checks.push({ name: \"Signature\", status: \"pass\", detail: `Verified against ${issuer}/.well-known/jwks.json.` });\n } catch (error) {\n const code = (error as { code?: string }).code ?? \"\";\n if (code === \"ERR_JWT_EXPIRED\" || code === \"ERR_JWT_CLAIM_VALIDATION_FAILED\") {\n checks.push({ name: \"Signature\", status: \"pass\", detail: `Verified against ${issuer}/.well-known/jwks.json.` });\n } else {\n checks.push({ name: \"Signature\", status: \"fail\", detail: describeVerifyError(code, issuer) });\n }\n }\n } else {\n checks.push({ name: \"Signature\", status: \"warn\", detail: \"Not checked. Pass --url to verify against a running issuer.\" });\n }\n\n return { kind: kindOf(payload), header, payload, checks };\n}\n\nfunction kindOf(payload: JWTPayload): TokenInspection[\"kind\"] {\n if (Array.isArray(payload.gty) && payload.gty.includes(\"client_credentials\")) return \"m2m\";\n if (\"email\" in payload || \"org_codes\" in payload || \"at_hash\" in payload || \"nonce\" in payload) return \"id\";\n if (\"scp\" in payload || \"permissions\" in payload || \"org_code\" in payload) return \"access\";\n return \"unknown\";\n}\n\nfunction describeVerifyError(code: string, issuer: string): string {\n if (code === \"ERR_JWKS_NO_MATCHING_KEY\") return `No key in ${issuer}'s JWKS matches this token's kid.`;\n if (code === \"ERR_JWS_SIGNATURE_VERIFICATION_FAILED\") return \"The signature does not match the token. It was changed after signing.\";\n if (code === \"ERR_JOSE_ALG_NOT_ALLOWED\" || code === \"ERR_JOSE_NOT_SUPPORTED\") return \"The token is not signed with RS256.\";\n if (code === \"ERR_JWKS_TIMEOUT\" || code === \"ERR_JOSE_GENERIC\") return `Could not fetch keys from ${issuer}.`;\n return `Verification failed (${code || \"unknown error\"}).`;\n}\n\nexport function formatSpan(seconds: number): string {\n const s = Math.max(0, Math.round(seconds));\n if (s < 60) return `${s}s`;\n if (s < 3600) return `${Math.floor(s / 60)}m ${s % 60}s`;\n if (s < 86400) return `${Math.floor(s / 3600)}h ${Math.floor((s % 3600) / 60)}m`;\n return `${Math.floor(s / 86400)}d ${Math.floor((s % 86400) / 3600)}h`;\n}\n","import type { Check } from \"./inspect.js\";\n\nconst SECRET_FORMAT = /^[a-zA-Z0-9]{40,60}$/;\n\nexport interface DoctorReport {\n url: string;\n checks: Check[];\n ok: boolean;\n}\n\nexport async function runDoctor(options: { url: string; env: Record<string, string | undefined> }): Promise<DoctorReport> {\n const url = options.url.replace(/\\/+$/, \"\");\n const checks: Check[] = [];\n let issuer: string | null = null;\n\n try {\n const health = (await (await fetch(`${url}/testkit/health`)).json()) as { issuer?: string };\n issuer = health.issuer ?? null;\n checks.push({ name: \"Issuer running\", status: \"pass\", detail: `${url} answers, issuer ${issuer}.` });\n } catch {\n checks.push({ name: \"Issuer running\", status: \"fail\", detail: `Nothing answers at ${url}. Start it with \"kinde-testkit start\".` });\n }\n\n if (issuer) {\n try {\n const discovery = (await (await fetch(`${url}/.well-known/openid-configuration`)).json()) as { issuer?: string };\n checks.push(\n discovery.issuer === issuer\n ? { name: \"Discovery\", status: \"pass\", detail: \"The discovery document names the same issuer.\" }\n : { name: \"Discovery\", status: \"fail\", detail: `Discovery says ${String(discovery.issuer)}, health says ${issuer}.` },\n );\n } catch {\n checks.push({ name: \"Discovery\", status: \"fail\", detail: \"Could not read /.well-known/openid-configuration.\" });\n }\n try {\n const jwks = (await (await fetch(`${url}/.well-known/jwks.json`)).json()) as { keys?: Array<{ kty?: string; use?: string }> };\n const usable = (jwks.keys ?? []).filter((key) => key.kty === \"RSA\" && key.use === \"sig\");\n checks.push(\n usable.length > 0\n ? { name: \"JWKS\", status: \"pass\", detail: `${usable.length} RS256 signing key at /.well-known/jwks.json.` }\n : { name: \"JWKS\", status: \"fail\", detail: \"No RSA signing key at /.well-known/jwks.json.\" },\n );\n } catch {\n checks.push({ name: \"JWKS\", status: \"fail\", detail: \"Could not read /.well-known/jwks.json.\" });\n }\n try {\n const users = (await (await fetch(`${url}/testkit/users`)).json()) as unknown[];\n checks.push(\n users.length > 0\n ? { name: \"Seed\", status: \"pass\", detail: `${users.length} seeded ${users.length === 1 ? \"user\" : \"users\"}.` }\n : { name: \"Seed\", status: \"warn\", detail: \"No seeded users. The sign-in page still accepts any email, but those users have no organization.\" },\n );\n } catch {\n checks.push({ name: \"Seed\", status: \"warn\", detail: \"Could not read /testkit/users.\" });\n }\n }\n\n const env = options.env;\n const configured = env.KINDE_ISSUER_URL?.trim().replace(/\\/+$/, \"\");\n if (!configured) {\n checks.push({ name: \"KINDE_ISSUER_URL\", status: \"fail\", detail: \"Not set. Set it to the testkit's issuer for test runs.\" });\n } else if (/\\.kinde\\.com$/i.test(new URL(configured, \"http://x\").hostname)) {\n checks.push({ name: \"KINDE_ISSUER_URL\", status: \"fail\", detail: `${configured} is a real Kinde domain. Tests would sign in against Kinde, not the testkit.` });\n } else if (issuer && configured !== issuer) {\n checks.push({ name: \"KINDE_ISSUER_URL\", status: \"fail\", detail: `${configured} does not match the testkit issuer ${issuer}. Token checks compare iss exactly.` });\n } else {\n checks.push({ name: \"KINDE_ISSUER_URL\", status: \"pass\", detail: `${configured}.` });\n }\n\n checks.push(\n env.KINDE_CLIENT_ID\n ? { name: \"KINDE_CLIENT_ID\", status: \"pass\", detail: \"Set. The testkit accepts any client ID.\" }\n : { name: \"KINDE_CLIENT_ID\", status: \"fail\", detail: \"Not set. Kinde's SDKs refuse to start without it.\" },\n );\n\n const secret = env.KINDE_CLIENT_SECRET;\n if (!secret) {\n checks.push({ name: \"KINDE_CLIENT_SECRET\", status: \"warn\", detail: \"Not set. Server-side SDKs, such as the Next.js SDK, need it.\" });\n } else if (!SECRET_FORMAT.test(secret)) {\n checks.push({ name: \"KINDE_CLIENT_SECRET\", status: \"fail\", detail: \"The Next.js SDK only accepts 40 to 60 letters and digits.\" });\n } else {\n checks.push({ name: \"KINDE_CLIENT_SECRET\", status: \"pass\", detail: \"Set, in the format Kinde's SDKs accept.\" });\n }\n\n if (issuer?.startsWith(\"https://\")) {\n checks.push(\n env.NODE_EXTRA_CA_CERTS\n ? { name: \"NODE_EXTRA_CA_CERTS\", status: \"pass\", detail: `${env.NODE_EXTRA_CA_CERTS}.` }\n : {\n name: \"NODE_EXTRA_CA_CERTS\",\n status: \"warn\",\n detail: \"The testkit serves HTTPS with a local certificate. Start your app with NODE_EXTRA_CA_CERTS set to it, or Node will refuse the connection.\",\n },\n );\n }\n\n const site = env.KINDE_SITE_URL;\n if (!site) {\n checks.push({ name: \"KINDE_SITE_URL\", status: \"warn\", detail: \"Not set. The Next.js SDK builds its callback URL from it.\" });\n } else if (!/^https?:\\/\\//.test(site)) {\n checks.push({ name: \"KINDE_SITE_URL\", status: \"fail\", detail: `${site} is not an http or https URL.` });\n } else {\n checks.push({ name: \"KINDE_SITE_URL\", status: \"pass\", detail: `${site}.` });\n }\n\n return { url, checks, ok: checks.every((check) => check.status !== \"fail\") };\n}\n\nexport function parseEnvFile(text: string): Record<string, string> {\n const values: Record<string, string> = {};\n for (const line of text.split(/\\r?\\n/)) {\n const match = /^\\s*(?:export\\s+)?([A-Za-z_][A-Za-z0-9_]*)\\s*=\\s*(.*)\\s*$/.exec(line);\n if (!match) continue;\n let value = match[2]!;\n if ((value.startsWith('\"') && value.endsWith('\"')) || (value.startsWith(\"'\") && value.endsWith(\"'\"))) {\n value = value.slice(1, -1);\n } else {\n value = value.replace(/\\s+#.*$/, \"\");\n }\n values[match[1]!] = value;\n }\n return values;\n}\n"],"mappings":";AAAA,SAAS,oBAAoB,WAAW,uBAAuB,iBAAkE;AAiBjI,eAAsB,aACpB,OACA,UAAgD,CAAC,GACvB;AAC1B,QAAM,SAAkB,CAAC;AACzB,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,SAA2C;AAC/C,MAAI,UAA6B;AAEjC,MAAI,QAAQ,MAAM,GAAG,EAAE,WAAW,GAAG;AACnC,WAAO,KAAK,EAAE,MAAM,UAAU,QAAQ,QAAQ,QAAQ,2CAA2C,CAAC;AAClG,WAAO,EAAE,MAAM,WAAW,QAAQ,SAAS,OAAO;AAAA,EACpD;AACA,MAAI;AACF,aAAS,sBAAsB,OAAO;AACtC,cAAU,UAAU,OAAO;AAAA,EAC7B,QAAQ;AACN,WAAO,KAAK,EAAE,MAAM,UAAU,QAAQ,QAAQ,QAAQ,qDAAqD,CAAC;AAC5G,WAAO,EAAE,MAAM,WAAW,QAAQ,SAAS,OAAO;AAAA,EACpD;AACA,SAAO,KAAK,EAAE,MAAM,UAAU,QAAQ,QAAQ,QAAQ,sDAAsD,CAAC;AAE7G,SAAO;AAAA,IACL,OAAO,QAAQ,UACX,EAAE,MAAM,aAAa,QAAQ,QAAQ,QAAQ,yCAAyC,IACtF,EAAE,MAAM,aAAa,QAAQ,QAAQ,QAAQ,GAAG,OAAO,OAAO,GAAG,CAAC,gDAAgD;AAAA,EACxH;AAEA,QAAM,SAAS,OAAO,OAAO,QAAQ,YAAY,OAAO,IAAI,WAAW,eAAe,IAAI,kBAAkB;AAC5G,SAAO,KAAK,EAAE,MAAM,OAAO,QAAQ,QAAQ,QAAQ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