Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c9fbffe
feat(cli-auth): add @clerk/cli-auth package
nicolas-angelo May 26, 2026
9f2ac6c
fix(cli-auth): address review feedback (keychain cleanup, http helper…
nicolas-angelo May 28, 2026
b0c5e9f
feat(cli-auth): add optional loginTimeoutMs config (default 120s)
nicolas-angelo May 28, 2026
06c2fba
feat(cli-auth)!: rename UserInfo to Identity and verifyApiKey to veri…
nicolas-angelo May 28, 2026
e456f81
feat(cli-auth)!: expand TokenKind to match @clerk/backend's TokenType
nicolas-angelo May 28, 2026
6dec304
feat(cli-auth): add @clerk/cli-auth/server export with cliAuth factory
nicolas-angelo May 28, 2026
cb59eef
docs(cli-auth): rewrite README and changeset for /server export and m…
nicolas-angelo May 28, 2026
dda694f
fix(cli-auth): preserve generic T through handle<T>() so verifyToken …
nicolas-angelo May 28, 2026
19b5599
fix(cli-auth): detect JWT-shaped machine tokens via typ header and su…
nicolas-angelo May 28, 2026
42f0bf4
refactor(cli-auth): replace as-unknown-as casts with real @clerk/back…
nicolas-angelo May 28, 2026
15dc52d
feat(cli-auth)!: flatten apiKeys block to top-level identityEndpoint …
nicolas-angelo May 28, 2026
16e9e49
feat(cli-auth)!: split Identity into discriminated union by subject p…
nicolas-angelo May 28, 2026
be75fc8
docs(cli-auth): split Discord into Community section and update Twitt…
nicolas-angelo May 28, 2026
a627954
docs(cli-auth): document Clerk CLI and curl paths for OAuth Applicati…
nicolas-angelo May 28, 2026
2927d6b
feat(cli-auth)!: extract handle as standalone export, reshape verifyT…
nicolas-angelo May 28, 2026
4e99176
fix(cli-auth): resolve eslint warnings in pre-existing code
nicolas-angelo May 28, 2026
14c07d2
test(cli-auth): add server integration suite and oauth_token unit test
nicolas-angelo May 28, 2026
14bec66
fix(cli-auth): make integration tests self-contained via clerk.machin…
nicolas-angelo May 28, 2026
46793f3
feat(cli-auth)!: narrow accepted tokens to api_key and oauth_token an…
nicolas-angelo May 29, 2026
c39913e
refactor(cli-auth)!: replace resolveToken kind with source field and …
nicolas-angelo May 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .changeset/loud-callbacks-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
'@clerk/cli-auth': minor
---

Add `@clerk/cli-auth`: reusable OAuth 2.0 + PKCE localhost-callback flow for adding Clerk authentication to Node.js CLIs.

The default export (`@clerk/cli-auth`) ships the CLI-side runtime: browser-based sign-in via a one-shot localhost callback server, token storage (keychain with file fallback, file, or memory), token refresh, revocation, `/oauth/userinfo` lookup, multi-credential resolution via `resolveToken()` (returns `{ token, source }` where `source` is `'arg' | 'env' | 'oauth'`), optional `identityEndpoint`-backed verification, and tunable timeouts (`loginTimeoutMs`, `requestTimeoutMs`).

The new `@clerk/cli-auth/server` subpath ships a backend route handler that consumers drop into any framework using Web `Request`/`Response` (Next.js App Router, Hono, Cloudflare Workers, Bun, Deno):

```ts
// lib/clerk-cli.ts
import { cliAuth } from '@clerk/cli-auth/server';
import { clerkClient } from '@clerk/nextjs/server';

export const auth = cliAuth({ client: clerkClient });

// app/api/cli/identity/route.ts
import { handle } from '@clerk/cli-auth/server';
import { auth } from '@/lib/clerk-cli';

export const GET = handle({ auth, accepts: ['api_key', 'oauth_token'] });
```

`cliAuth({ client | clientConfig })` binds a `@clerk/backend` client once and returns an instance exposing `verifyToken(token)`, `verifyTokenFromRequest(request)`, `resolveAuthInfo(ctx)`, and `getClerk()`. The standalone `handle({ auth, accepts, verifyToken?, resolveAuthInfo? })` produces a route handler that auto-detects token type, gates against `accepts`, verifies via `@clerk/backend`'s `verifyMachineAuthToken`, and returns an `Identity` JSON payload. Override the verification or resolution steps per-route by passing the corresponding callbacks.

`accepts` recognizes `'api_key'` (covers user, org, and machine subjects), `'oauth_token'` (opaque `oat_*` or RFC 9068 `at+jwt` JWTs), or `'any'`. The narrowed `TokenKind` excludes Clerk session tokens and M2M tokens — neither is a CLI credential.
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ chrome-extension:
- changed-files:
- any-glob-to-any-file: packages/chrome-extension/**

cli-auth:
- changed-files:
- any-glob-to-any-file: packages/cli-auth/**

clerk-js:
- changed-files:
- any-glob-to-any-file: packages/clerk-js/**
Expand Down
8 changes: 8 additions & 0 deletions packages/cli-auth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.log
.DS_Store
.idea
node_modules
dist
coverage
.env
.env.local
2 changes: 2 additions & 0 deletions packages/cli-auth/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!/dist/**/*
21 changes: 21 additions & 0 deletions packages/cli-auth/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Clerk, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading
Loading