Persistent classes in an application implement the entities of the business problem. In Java SDK, two default persistence classes with their implementations are provided. On the other hand, if a developer wants his specific implementation, he can define his custom implementation by connecting to their respective database system.
Implementing OAuth Persistence
Once the application is authorized, OAuth access and refresh tokens can be used for subsequent user data requests to Zoho CRM. Hence, they need to be persisted by the client app.
The persistence is achieved by writing an implementation of the inbuilt ZohoPersistenceHandler interface, which has the following callback methods.
- saveOAuthData(ZohoOAuthTokens tokens) — invoked while fetching access and refresh tokens from Zoho.
- deleteOAuthTokens()— invoked before saving the newly received tokens.
- getOAuthTokens() — invoked before firing a request to fetch the saved tokens. This method should return ZohoOAuthTokens object for the library to process it.
Our Java SDK provides two sample implementations of ZohoPersistenceHandler interface within the client library as shown below:
You could use any of the above mentioned interface implementations provided in the library.
ZohoOAuthFilePersistence
ZohoOAuthFilePersistence uses a local properties file to write and read the OAuth tokens data. If you are using this persistence, then you need to provide the following attributes and their values in the oauth_configuration.properties file.
ZohoOAuthDBPersistence
ZohoOAuthDBPersistence uses a custom MySQL persistence. To use this, you should make sure of the following,
- MySQL should be running in the same machine serving at the default port 3306.
- The database name should be "zohooauth".
- There must be a table "oauthtokens" with the columns "useridentifier" (varchar), "accesstoken" (varchar), "refreshtoken" (varchar) and "expirytime" (bigint).
If you are using ZohoOAuthDBPersistence, then you need to provide the following attributes and values in the oauth_configuration.properties file.