Your OAuth Client details should be given to the SDK as a property file. In the SDK, you need to configure a file named oauth_configuration.properties. Please place the respective values in that file. You can place it under resources folder from where the SDK is used.
Property File
Based on your domain(EU,CN), please change the value of "crm.iamurl". Default value set as US domain.
In oauth_configuration.properties file:
- [zoho]
- crm.iamurl=
- crm.clientid=
- crm.clientsecret=
- crm.redirecturl=
- crm.clientid,
crm.clientsecret and crm.redirecturl are your OAuth client’s
configurations that you get after registering your Zoho client.
- crm.iamurl is
the accounts URL. It may be accounts.zoho.com or accounts.zoho.eu. If
the crm.iamurl is not specified, by default the URL will
be accounts.zoho.com.
Please fill the values for the following keys alone.
In configuration.properties file:
- [crm]
- api.url=
- api.user_identifier=
- api.tokenmanagement=
- [mysql]
- username=
- password=
- api.url is the URL used to call APIs. By default, the URL is www.zohoapis.com.
- api.user_identifier will
be empty by default. For single user authentication, this key can be
filled with the respective email id, so that all calls happens by using
this user's authentication.
- api.tokenmanagement is
given as a measure to manage and maintain tokens. If tokenmanagement is
not provided, then sdk's default implementation(mysql) will be
followed.
- username and password can be given here if you already have one created for your MySQL.
The above keys specified in configuration.properties file are all optional.
Token Storage Mechanism
To use the default token storage provided by the SDK, the following are to be done
- Mysql should be running in default port in localhost.
- Database with name zohooauth should be created and a table with below configurations should be present in the database. Table, named "oauthtokens", should have the columns "useridentifier" (varchar) "accesstoken" (varchar), "refreshtoken" (varchar) and "expirytime" (bigint).
- Once the configuration is set, storage and retrieval of tokens will be handled by the SDK.
- If the user wants to utilize their own mechanism, they can mention it in configuration.properties by providing the respective module in api.tokenmanagement.
This module should contain the below methods,
- saveOAuthTokens(token_obj)
- updateOAuthTokens(token_obj)
- Irrespective of response, the next execution happens. So care should be taken by the user in handling their module.
- getOAuthTokens()
- The
expected response for this method : JSON array containing json response
with expirytime, refreshtoken and accesstoken fields.
Note
All methods should return promise.
saveOAuthtoken & updateOAuthTokens will be called with JSON parameters, which contain fields given below,
- access_token
- refresh_token
- expires_in
Sample code for custom token management getOAuthTokens()
- tokenmanagement.getOAuthTokens = function(user_identifier){ //expires in : 1527839622728
- return new Promise(function(resolve,reject){
- var result = {};
- result.accesstoken = '1000.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxx';
- result.expirytime = 15278396227289
- result.refreshtoken = '1000.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxx';
- var result_array =[];
- result_array.push(result);
- resolve(result_array);
- });
- }