Persistence - C# SDK

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 an implementation of the inbuilt  IZohoPersistenceHandler  interface, which has the following callback methods.
  • SaveOAuthTokens(ZohoOAuthTokens tokens)  — invoked while fetching:
    • access and refresh tokens using grant token.
    • access token using refresh token.
  • 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 C# SDK provides three sample implementations of  IZohoPersistenceHandler  interface within the client library. They are:
  • ZohoOAuthFilePersistence
  • ZohoOAuthDBPersistence
  • ZohoOAuthInMemoryPersistence
The name (along with its assembly comma seperated) of the implemented class or the handlers provided by the SDK should be given as value for the key peristence_handler_class.

Like ' persistence_handler_class=<persistence_handler_class, assembly_name> ', under the  oauth_configuration  section in the app.config file.


Note

  • If the persistence handler class is not specified,  InMemory Persistence  handler handles the persistence implementation by default.
  • Pre-defined persistence handler classes belong to the assembly ZCRMSDK.

ZohoOAuthFilePersistence

This method of persistence uses a local file to write and read the OAuth tokens.

The complete path of the file to be used by the library to write and read the tokens should be specified under the oauth_configuration section in app.config file as the value of the key  oauth_tokens_file_path .

ZohoOAuthDBPersistence

This method of persistence 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(100)),  accesstoken  (varchar(100)),  refreshtoken  (varchar(100)) and  expirytime  (bigint).

ZohoOAuthInMemoryPersistence

Uses a singleton class to store and retrieve tokens. Default implementation and requires no external file.


Note

  • ZohoOAuthFilePersistence and ZohoOAuthInMemoryPersistence implementations only support to store and refresh only a single user’s token. Hence they should be used only if the app accesses Zoho APIs on behalf of a single user.
  • In case if the app has to support for multiple users, please use the ZohoOAuthDBPersistence or write your own implementation of IZohoPersistenceHandler.



    • Related Articles

    • 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 - 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 ...
    • C# SDK - An Overview

      C# SDK offers a way to create client C# 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 ...
    • 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 ...
    • Configuration - Python SDK

      Before you get started with creating your python application, you need to first authenticate the app with Zoho. And to do that there are some configuration procedures that need to be in place. There are two methods in which you can authenticate your ...