This is a sample reference code in Java to help you understand the OAuth authorization flow for Zoho Desk Rest APIs. If needed, You can reuse this same code in your Java application or can reuse the logic using any other language of your preference to make calls to Zoho Desk APIs.
Refer OAuth Authorization from Zoho Desk API Doc (To access appropriate reference links replace the
".com"
with your respective domain.) sample US doc link: https://desk.zoho.com/support/APIDocument.do#OauthTokens
To be able to access Zoho Desk functionalities through your application using Zoho Desk Rest APIs, you must authenticate your application. To do this, first, pass a key-value configuration pair in oauthConfig.properties file and pass this property file path as value for zdesk-init-file system property key as a VM argument.
Required configuration
is_selfclient
is true you can ignore the key redirect_uri
because self client doesn't require a redirect url.This sample reference code provides ZohoOAuthPersistenceInterface class. If you want to use an implementation of your choice, you can do so by implementing this given interface.
Implementing OAuth persistence
After the client application is authorized, OAuth access and refresh tokens can be used for making subsequent data requests to Zoho Desk. Therefore, the tokens must be persisted by the application.
You can achieve this persistence by writing an implementation of the predefined ZohoPersistenceHandler interface, which has the following callback methods:
saveOAuthData(ZohoOAuthTokens tokens) - This function helps to store OAuth token data in the persistence.
deleteOAuthTokens(String mailId) - This function helps to delete given user OAuth token data from the persistence.
getOAuthTokens(String mailId) - This function helps to get given user OAuth token data from the persistence.
isUserAuthenticated(String mailId) - Identifies whether the current user is authenticated.
The sample reference code provides sample implementations of the ZohoPersistenceHandler interface using file persistence. Refer ZohoOAuthFilePersistence class.
Implement com.zoho.oauth.client.ZohoPersistenceHandler if you need to persist OAuth data. Also specify the classpath in persistence_handler_class
Key under oauthConfig.properties file.
Refer: https://desk.zoho.com/support/APIDocument.do#self-client
Refer: https://desk.zoho.com/support/APIDocument.do#redirection
DeskAPIHandler class has sample implementation about how to make Desk API call using the generated token information.
Demo For using OAuth Webclient client: https://workdrive.zohoexternal.com/external/6Oxchx1jp6Q-J8HFH