Desk Java SDK
Help Home   /   Java SDK   /   Persistence

Configuring Persistence

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.

Default Persistence Implementations

The Zoho Desk Java SDK supports two types of persistence by default: file persistence and database persistence.

We have created a sample of each persistence implementation using the ZohoPersistenceHandler interface and included the link to access them in the sections below. The sample code is primarily for your reference and is not suited for use in large-scale applications. However, if you want to use the sample code in your application, you can do so by making the modifications required.


The ZohoOAuthFilePersistence class uses a file to write and read data from OAuth tokens. If you choose this way, make sure to also provide the following attributes and their corresponding values in the property file:

  • persistence_handler_class=com.zoho.oauth.clientapp.ZohoOAuthFilePersistence
  • oauth_tokens_file_path=relative path of the "{oauthtokens}.properties" file in the workspace

To access the sample implementation of ZohoOAuthFilePersistence click here.


This method of persistence uses a custom MySQL persistence. When you first invoke a function in the ZohoOAuthDBPersistence class, tables for oauthtokens will be created in the zohooauth database.

If you choose to use ZohoOAuthDBPersistence, you need to provide the following attributes and values in the property file:

  • persistence_handler_class=com.zoho.oauth.clientapp.ZohoOAuthDBPersistence
  • mysql_username=root
  • mysql_password=
  • mysql_server_url={give valid MySQL server URL. for eg: localhost:3306}

and also please be ensure that java mysql connector is added in your project. To access the sample implementation of ZohoOAuthDBPersistence click here.