Add OAuth support#4
Draft
victor-nitu wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Zendesk is deprecating API token authentication (announcement). Phase 1 begins July 28, 2026 (tokens unused for 30 days auto-deactivate; new accounts can't create tokens at all). Phase 3 on April 30, 2027 force-deactivates all remaining tokens.
This PR adds OAuth 2.0 client credentials support to our
zdeskfork so we can migrate off API tokens before the deadline, with a feature flag controlling which auth method each caller uses.What changed
zdesk/zdesk.pyuse_oauthbool onZendesk.__init__. WhenTrue, requiresclient_idandclient_secret— raisesValueErrorat construction time if either is missing, rather than failing silently at the first API call.fetch_oauth_token(client_id, client_secret)method. POSTs to/oauth/tokenswithgrant_type=client_credentials, sets the Bearer token on the session, and returns the full response dict (includingexpires_in). RaisesAuthenticationErroron non-200.use_oauth=False(default) behaves exactly as before.tests/test_oauth.py— 12 new unit tests (all mocked, no real Zendesk calls):TestFetchOauthToken: correct endpoint + payload, Bearer header set,expires_inreturned,AuthenticationErroron failureTestUseOauthConstructor: token fetched onuse_oauth=True,ValueErroron missing credentials, API token auth active onuse_oauth=FalseUsage
Since each Celery task instantiates its own client, the feature flag just controls which arguments are passed at construction — no runtime toggling needed.
Test plan
pytest tests/test_oauth.py— 12 tests, all passuse_oauth=Trueand valid credentials; confirmAuthorization: Bearer <token>header is set andclient.authisNoneuse_oauth=Trueand missingclient_secret; confirmValueErroris raised immediatelyuse_oauth=Falseand API token creds; confirm existingemail/tokenbasic auth is used and no Bearer header is set