Now that you have defined the OAuth configuration file and OAuth persistence handler class, you can move on to the next step, which is initializing your app. Copy the SDK configuration key-value pairs required and paste them into a property file. Enter the path of the file as the value of the desk.sdk.config system property key.
On your first attempt to get the ZohoOAuthClient instance using ZohoOAuthClient.getInstance();, the SDK is automatically fetched values from the desk.sdk.config system property and initialized.
The Zoho API Console gives you the option to directly generate grant tokens for users. This option comes in handy if your application is configured to use only one Zoho Desk user's credentials for all operations. This option also proves to be useful while testing your application.
To generate the grant token, perform the following steps:
Alternatively, you can also generate the grant token using your Java client, through the SDK. Here's how you do it.
To generate the grant token in this method, perform the following steps. We used a Java servlet to help you understand the procedure better.
To get the access and refresh tokens after obtaining the grant token, include the following code snippet in a Java file and execute it from your main class.
If you generated the grant token through the API Console (Self Client option), the client ID and client secret are separately generated. Use these client ID and client secret details to configure the SDK.
ZohoOAuthClient client = ZohoOAuthClient.getInstance(); String grantToken = "paste the self authorized grant token here"; ZohoOAuthTokens tokens = client.generateAccessToken( grantToken ); String accessToken = tokens.getAccessToken(); String refreshToken = tokens.getRefreshToken(); System.out.println("access token: " + accessToken + ", refresh token: " + refreshToken);
After this code is executed, the access and refresh tokens are created and stored in a location that varies according to the persistence class you use.
To generate an access token from the refresh token, use the following code snippet.
ZohoOAuthClient client = ZohoOAuthClient.getInstance(); client.generateAccessTokenFromRefreshToken( refreshToken, userMailId );