M2M Token only authentication in Clerk Middleware
維護者通常 1 天內回覆
@wobsoriano 已經在處理了。
開始於 2026年9月29日。
評估
這個 Issue 還沒有評估資料。
描述
Preliminary Checks
-
I have reviewed the documentation: https://clerk.com/docs
-
I have searched for existing issues: https://github.com/clerk/javascript/issues
-
I have not already reached out to Clerk support via email or Discord (if you have, no need to open an issue here)
-
This issue is not a question, general help request, or anything other than a bug report directly related to Clerk. Please ask questions in our Discord community: https://clerk.com/discord.
Reproduction
https://github.com/x-delfino/clerk-fastify-issue-repro
Publishable key
pk_test_dG91Y2hlZC1mb3dsLTk5MDYuY2xlcmsuYWNjb3VudHMuZGV2JA
Description
I'm trying to use M2M tokens to authenticate one machine to another, without any subsequent backend API access. I'm testing this with the clerk fastify plugin, but I don't think the issue is necessarily specific to that package
Steps to reproduce:
- Create M2M Machines in Clerk:
MachineA: no scopesMachineB: scope forMachineA
- Setup workspace (using
MachineAsecret key):
git clone https://github.com/x-delfino/clerk-fastify-issue-repro
cd clerk-fastify-issue-repro
pnpm install
export CLERK_MACHINE_SECRET_KEY="ak_XXXXXXXXX"
pnpm run serve
- Generate token for
MachineB - make HTTP request:
TOKEN="MACHINE_B_TOKEN"
curl -H "Authorization: Bearer $TOKEN" localhost:8080/protected
Expected behavior:
To receive response:
{"message":"Machine authenticated successfully","subject":"mch_XXXXXXXXX","scopes":["mch_XXXXXXXXX"]}
Actual behavior:
Response received:
{"statusCode":500,"error":"Internal Server Error","message":"Publishable key is missing.\n\nTo create a new Clerk app, run:\nnpx clerk@latest init\n\nTo use an existing Clerk app, run:\nnpx clerk@latest link\nnpx clerk@latest env pull\n\nFor production keys, run:\nnpx clerk@latest env pull --instance prod\n\nOr copy keys from https://dashboard.clerk.com/~/api-keys into your .env file."}
Providing CLERK_PUBLISHABLE_KEY changes the response to:
{"statusCode":500,"error":"Internal Server Error","message":"Missing Clerk Secret Key. Go to https://dashboard.clerk.com and get your key for your instance."}
Detail:
The clerk middleware for fastify hardcodes the acceptsToken to 'any':
When the token is then processed, as it's not explicitly M2MToken or ApiKey - it tries to load the publishable key:
I patched the fastify clerk middleware to allow the acceptsToken key to be provided:
const requestState = await clerkClient.authenticateRequest(req, {
...clerkOptions,
secretKey,
publishableKey,
proxyUrl: resolvedProxyUrl,
// acceptsToken: 'any',
});
Allowing me to update my sample code to:
fastify.register(clerkPlugin, { acceptsToken: "m2m_token" })
Allowing me to receive and validate M2M tokens using M2M tokens only
However, this isn't type correct. ClerkFastifyOptions, through a chain of intersections, doesn't pull in acceptsToken from AuthenticateRequestOptions
I'm not sure the best way to proceed from here as changes may affect more than fastify
Environment
System:
OS: macOS 26.5
CPU: (10) arm64 Apple M4
Memory: 134.00 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 26.10.0 - /nix/store/xs1l2nzllqp7imnhpd2n6cm0m70yzp10-nodejs-26.10.0/bin/node
npm: 11.19.1 - /nix/store/xs1l2nzllqp7imnhpd2n6cm0m70yzp10-nodejs-26.10.0/bin/npm
pnpm: 11.27.0 - /nix/store/gjkd8wjh079v7i5j2rb8y0b5r19addpa-pnpm-11.27.0/bin/pnpm
Browsers:
Safari: 26.5
npmPackages:
@clerk/fastify: ^3.1.82 => 3.1.82
@types/node: ^26.6.3 => 26.6.3
fastify: ^5.12.5 => 5.12.5
typescript: ^7.0.2 => 7.0.2
- 主要語言
- TypeScript
- 星號
- 1.8k
- 分支
- 484
- 平均合併
- 1 天 7 小時
- 30 天內合併 PR
- 350
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
clerk/javascript 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 75/100
clerk/javascript#10548 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
clerk/javascript#10547 ·
維護者通常 1 天內回覆
-
<SignIn />: first "Use email" click switches back to phone when `initialValues.phoneNumber` is set可能已有人在做 @twicestruck 於 6 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 74/100
clerk/javascript#10487 ·
維護者通常 1 天內回覆
-
useLoadedIsomorphicClerk misses "ready" when a ClerkProvider remounts after clerk-js has loaded — <ClerkLoading> never resolves可能重新可做 關聯的 PR 已關閉且未合併。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
clerk/javascript#10462 ·
維護者通常 1 天內回覆
-
ClerkAPIError drops meta.lockout_expires_in_seconds from user_locked errors可能已有人在做 @umeraamir69 於 11 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
clerk/javascript#10026 · 2 則留言 ·
維護者通常 1 天內回覆
相似的 Issue
-
mobile-app
難度 2/5 1-3 小時 新手友好度 74/100
Open-Locker/Open-Locker#352 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
leanprover-community/lean4game#589 ·
維護者通常 2 天內回覆
-
check:passed streams:add
難度 1/5 1 小時以內 新手友好度 68/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 82/100
維護者通常 1 天內回覆