Token Persistence - PHP SDK
Token persistence refers to storing and utilizing the
authentication tokens that are provided by Zoho. There are three ways
provided by the SDK in which persistence can be applied. They are file
persistence, DB persistence (default) and Custom persistence.
Database Persistence
In
case the user prefers using database persistence, MySQL can be used.
The DB persistence mechanism is the default method in PHP SDK.
- The MySQL should run in the same machine.
- The database name should be zohooauth.
- There must be a table oauthtokens with columns
- useridentifier (varchar(100))
- accesstoken (varchar(100))
- refreshtoken (varchar(100)),
- expirytime (bigint)
File Persistence
In
case of file persistence, the user can also set up persistence as a
file in the local drive, he needs to set the file path in the token_persistence_path, of the $configuration array (key-value pair).
- In case the user uses file persistence, he has to create an empty file with the file name "zcrm_oauthtokens.txt".
- The file path of the folder containing the zcrm_oauthtokens.txt file must be provided in token_persistence_path.
For example, if the file has to be under folder "TokenStorage", then
- token_persistence_path="{path/to/TokenStorage}"
Note that we must not include "zcrm_oauthtokens.txt" in the path.
Custom Persistence
Starting
from the PHP SDK version 2, the user can have his own implementation of
persistence. The user needs to provide the file path of the PHP file
that implements the custom persistence, in the persistence_handler_class key of the configuration array (key-value pair).
- The user-created PHP file for persistence must have the same file name and class name. For example, if the file name is "Customdb.php", then the class must be "class Customdb".
- The class must implement ZohoOAuthPersistenceInterface.
The user can write an implementation of the inbuilt ZohoPersistenceHandler interface, which must contain the following callback methods.
- saveOAuthData(ZohoOAuthTokens tokens) - invoked while fetching access and refresh tokens from Zoho.
- deleteOAuthTokens($userEmailId) - invoked before saving the newly received tokens.
- getOAuthTokens($userEmailId) -
invoked before firing a request to fetch the saved tokens. This method
should return ZohoOAuthTokens object for the library to process it.
Related Articles
PHP SDK - An Overview
PHP SDK offers a way to create client PHP applications that can be integrated with Zoho CRM. This SDK makes the access and use of necessary CRM APIs with ease. In other words, it serves as a wrapper for the REST APIs, making it easier to use the ...
Initialization - PHP SDK
The app would be ready to be initialized after defining the configuration array. The user can now proceed to generate the required tokens to run the app. The generation of the grant token can be done using two methods. Self-Client Redirection-based ...
Configuration - PHP SDK
To access the CRM services through SDK, the client application must be first authenticated. This can be done by passing a key-value configuration pair to the initialization process. The $configuration array must be created. It will contain the ...
Persistence - C# SDK
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 ...
Persistence - Java SDK
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 ...