Repository navigation
fix(connectors): send Ahrefs client credentials in the token request body - #9826
Conversation
…body A dynamic-client method can now declare token_request_auth_method. Registration uses it, token requests honor it even for a client stored under another method, and a new connect registers afresh instead of reusing such a client. Ahrefs declares client_secret_post, as its OAuth guide asks. Notion's declaration was ignored for dynamic clients until now, so it is removed to keep Notion as is.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
|
Preview update published for development build |
Problem
Ahrefs connect has never succeeded. The OAuth round trip completes, then the token exchange fails and the desktop shows "Could not connect Ahrefs. Try again."
Production evidence (Vercel
api-paradev, 2026-11-16, five attempts by one customer):token_endpoint_auth_methods_supported, sopickAuthMethodregistered the client asclient_secret_basic. Ahrefs accepts that and returns base64 ids and secrets that contain+,/and=.exchangeCodethen sentAuthorization: Basic base64(id:secret)without form-encoding the id and secret, and sent noclient_idin the body.client_idandclient_secretin the form body. It does not mention Basic.Fix
A dynamic-client method can now set
token_request_auth_methodinconnectors.json. Before this PR, only static clients used that field. When a dynamic method sets it:client_secret_basicrows stay, and new connects stop using them.ahrefs_mcpsetsclient_secret_post.notion_mcphadtoken_request_auth_method: client_secret_basic. Before this PR the code ignored that field for dynamic clients, so the PR removes it, and Notion keeps its current behavior. (Notion uses a client id metadata document and has no secret to send.)Probes (public endpoints, throwaway clients, no secrets logged)
token_endpoint_auth_method: client_secret_postworks: Ahrefs echoesclient_secret_postand returns a secret. It grants onlyauthorization_code, notrefresh_token.POST https://ahrefs.com/oauth/tokenwith no client id anywhere returnsNo client_id. With only a Basic header, Ahrefs gets past that check, so it does read Basic.invalid_grant(body or Basic, correct or wrong secret, unknown client). Ahrefs checks the code before the client, so a fake code cannot tell the variants apart.Not confirmed: whether body credentials are what fixes
invalid_grantfor a real code. One possible cause is the+in the Basic value being decoded as a space. Only a real authorization can confirm this.Not changed
$.token_type, so every Ahrefs connection has the account idBearer. Connect works, because user connections are keyed by user. ButgrantSharedWithAnotherConnectionwill treat any two users' Ahrefs connections as sharing a grant. I need a real token response to find a better field.expires_inis returned), the connection is markedneeds_reauth, which is expected.https://api.ahrefs.com/mcp/mcp) acceptsAuthorization: Bearer: a bogus token getsAccess denied: MCP token is invalid. I could not test a valid token.Tests
client-identity.test.tsadds tests for Ahrefs:client_secret_post;client_secret_basicclient;client_idandclient_secretin the body, with no Basic header;Three of these tests fail without the fix.
Manual test (needs an Ahrefs Lite+ account)
/api/connectors/callback/ahrefs_mcpreturns notoken exchange failed.public-domain-rating-freefor a domain). It should return data, notAccess denied.$.token_typeidentity.End-to-end evidence (local stack, real Ahrefs servers) — 2026-11-16
Setup: local API (
:8261) and web (:8260) from this branch, on this workspace's own Neon branch (non-primary, branched from production today). Outbound fetches from the API were logged by a--requirepreload, and secrets, codes, verifiers and tokens are redacted to their length. The browser was a separate Chrome, driven over CDP and signed in as the local dev admin. The desktop dev app (renderer:8265) received the deep links. A token stand-in on127.0.0.1:8299replacedhttps://ahrefs.com/oauth/tokenonly for the runs marked "stand-in".1. Connect up to the Ahrefs authorize page (no stored client)
GET /api/connectors/ahrefs_mcp/connect?organizationId=…&method=oauth2&plugin=ahrefsreturns 302 to the real Ahrefs authorize page ("Sign in to Ahrefs").Ahrefs accepts
client_secret_postand thehttp://localhostredirect URI at registration. The authorize page shows the same sign-in page for this client, for a redirect URI that was never registered, and for an unknown client. So Ahrefs checks the redirect URI only after sign-in, and that part needs a real account.2. The token request the fix sends (stand-in), compared with Ahrefs' OAuth guide
grant_type=authorization_codeclient_id(same as step 1)redirect_uri(same as step 1)codecode_verifierclient_secret(web apps)resource(RFC 8707)The same request on main, captured the same way:
authorization: Basic base64(gI876bzjGDGeugiFQw4PJw==:<redacted>), and the body has noclient_idand noclient_secret.Replay of this request shape against the real
https://ahrefs.com/oauth/tokenwith a fake code:400 {"error":"invalid_grant"}. It is the same with noresource, with a wrong secret, with an unknown client, and with an unknown extra field. So Ahrefs ignores extra fields, and a fake code cannot tell the auth variants apart.3. Stored-client paths (real DB rows, real Ahrefs registration)
client_secret_postclient_secret_basicclient (real Ahrefs registration, scopes{apiv3-mcp})client_secret_postclient; a second connect reuses that one with 0 registrationsxvrW…from the state?connected=1; the connection row hasoauth_client_id=xvrW…,external_account_id=Bearer, no refresh token,expires_inappliedCNZf…(basic row)?connected=14. Regression: other dynamic connectors, main vs this branch
client_secret_post→ mcp.linear.app/authorizeclient_secret_post→ sameclient_secret_post→ mcp.notion.com/authorizeclient_secret_post→ sametoken_request_auth_method: client_secret_basicline keptclient_secret_basicOn main the Notion line had no effect for dynamic clients. Under this PR it would switch Notion to Basic, so removing it keeps Notion as on main. (In production, Notion uses a client id metadata document over https, so it has no secret and the field does not apply there either.)
5. Negative paths
error=access_denied)/connect/ahrefs_mcp?error=oauth_deniedinvalid_grant(real Ahrefs, fake code)/plugins/ahrefs?error=token_exchange_failed→ desktop deep linkinvalid_client(stand-in)forgetClient)/connect/ahrefs_mcp?error=invalid_state/connect/ahrefs_mcp?error=invalid_state, no token requestDesktop toasts were checked by opening the dev app's own deep link (
superset-<workspace>://plugins/ahrefs?…). Results:token_exchange_failedshows "Could not connect Ahrefs. Try again.",oauth_deniedshows "You declined the Ahrefs authorization request.",invalid_stateshows "That Ahrefs sign-in link expired. Try connecting again.", andconnected=1shows "Connected Ahrefs".Found along the way, not changed by this PR:
/connect/<slug>?error=…and?connected=1on web show no toast for any connector (Linear included). The effect runs, because the query is cleared, but nothing is rendered.resolveCallback(deny, bad state) goes to web/connect/<slug>, not to the desktop plugin page.superset://, but the dev desktop app registerssuperset-<workspace>://.6. Plugin proxy and disconnect
With the plugin installed and the stand-in connection stored,
tools/callthrough/mcp/plugins/superset/ahrefssendsAuthorization: Bearer <stored token>tohttps://api.ahrefs.com/mcp/mcp. Ahrefs answersAccess denied: MCP token is invalid, as expected for a fake token.connectors.disconnectmarks the rowdisconnect_reason=user, and the proxy then tells the agent to open the connect URL.Still unconfirmed
A real code exchange, a real token, and a real tool call. These need an Ahrefs account to sign in and approve.