add support for refresh tokens#593
Open
zendesk-mradmacher wants to merge 1 commit into
Open
Conversation
1b028ca to
e1d2604
Compare
b60624d to
9ad3fc8
Compare
bquorning
reviewed
Nov 6, 2025
482a435 to
544eee2
Compare
add dedicated unauthorized error allow token refreshing middleware to be enabled in configuration
544eee2 to
0019bf4
Compare
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.
Add support for refreshing OAuth access token.
When you need some inspiration, consult how the token refresh flow is done by Restforce, the public gem for Salesforce REST API.
I add a new
ZendeskAPI::TokenRefresherservice, to obtain new access and refresh tokens. It takes client configuration as a parameter. When tokens get refreshed, the client configuration is updated, so the next requests are issued using the newly obtained access token. Also a block is yielded with new access and refresh tokens, so they could be stored for further use.The alternative solution is to use
ZendeskAPI::Middleware::Response::TokenRefresher, to start the process of token refreshing each time when the API responds with 401. The middleware also updates the client configuration. It requires a callback to be configured. The called is called whenever new tokens are obtained to allow storing them for further use.There is a configuration option to enable middleware usage.
How to test?
In Admin Center, Apps and Integrations / APIs / OAuth Clients create a new client. Note client id and secret and redirect URL. The redirect URL can be any address.
The encoded URL looks like https%3A%2F%2Fexample.com.
expires_inis chosen to be 5 minutes (the lowest possible value), to make the access token expire quickly, for easier testing.tokensin the following format: