Skip to content

feat: support the OAuth client credentials grant - #340

Open
christiansmithdeveloper wants to merge 1 commit into
justeat:developfrom
enfonica:feature/oauth-client-credentials
Open

feat: support the OAuth client credentials grant#340
christiansmithdeveloper wants to merge 1 commit into
justeat:developfrom
enfonica:feature/oauth-client-credentials

Conversation

@christiansmithdeveloper

Copy link
Copy Markdown

Closes #339

Why

Zendesk is retiring API token (basic auth) authentication, and recommends the client credentials grant for server-to-server integrations where no user is present to authorise access.

The client already accepts an OAuth token (ZendeskOptions.OAuthTokenBearer header) but has no way to obtain or renew one. That's a blocker for client credentials specifically, because:

  • the grant issues no refresh token — an expired token is replaced by re-running the grant;
  • access tokens expire (30 minutes by default, 48 hours max; clients created on/after 30 Apr 2026 get 30 minutes applied automatically);
  • OAuthToken is assigned once at registration, so a configured token inevitably goes stale.

What

Adds first-class support for the client credentials grant:

  • ClientId / ClientSecret / Scope / token-lifetime options on ZendeskOptions
  • ZendeskTokenProvider — obtains tokens from POST /oauth/tokens, caches them, and renews shortly before expiry (thread-safe, single-flight)
  • ZendeskOAuthDelegatingHandler — sets a current token per request on the existing zendeskApiClient named client, so a renewed token is picked up without recreating the client
  • AddZendeskClientWithClientCredentials(...) registration overload

Existing basic-auth and static OAuth-token behaviour is unchanged. Version bumped 7.0.77.1.0, and the README documents the new option.

Testing

  • Unit tests added for the token provider (mint, cache, renewal, single-flight concurrency, error handling, secret-not-leaked-in-errors) and the delegating handler (header set, replaced, per-request). Full suite passes (440 tests).
  • Verified end-to-end against a live Zendesk instance — token minting, caching, ticket read, and ticket creation.

Note for reviewers

Zendesk's docs describe this grant as requiring grant_type and client_secret only, but the endpoint rejects the request with invalid_request: 'client_id' required. unless client_id is also sent. This is handled, and confirmed against a live instance.


🤖 Implementation assisted by AI; written, reviewed, and tested by a human before submission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant