Access Token is used for Authentication in ZOHO Applications. Access Token is Expire Every 1 hour so we need to generate a new access token from the the Refresh code and refresh has an unlimited lifetime until it is revoked by the end-user.
We can Generate Refresh Token Using two Method :
Step-1 : To register client use below URL,
https://api-console.zoho.in/
Step-2 : Enter the following details:
Step-3 : After click on enter “Create Button“, You will receive Client ID and Client Secret Credentials,
Step-4 : Enter below authorization URL in postman,
https://accounts.zoho.in/oauth/v2/auth?&scope={scope}&client_id={client_id}&response_type=code&access_type={access_type} &redirect_uri={redirect_uri}
Pass below parameters with postman to get grant token( code )
Step-5 : Copy above URL from “postman” and paste into browser to get grant token( code ).
Copy code as given below image,
Step-6 : Now we make POST request using below URL:
https://accounts.zoho.in/oauth/v2/token?code={grant_token}&client_id={client_id}&client_secret={client_secret}&grant_type=authorization_code&redirect_uri={redirect_uri}
Pass below pameters with postman to Access Token and Refresh Token
Now we get refresh code and access code in response
Here access_token will be expired in an hour.
refresh_token will be valid for life time.
Step-7 : After access_token is expired, create new token using the refresh_token. You need to POST request using below URL:
https://accounts.zoho.in/oauth/v2/token?client_id={client_id}&client_secret={client_secret}&grant_type=refresh_token&refresh_token={refresh_token}
class functions { function getAuthorizationCode() { global $authorize_url, $client_id, $scope, $redirect_uri, $scope; $authorize_url = "https://accounts.zoho.com/oauth/v2/auth?&scope".$scope."&client_id=".$client_id."&response_type=code&access_type=offline&redirect_uri=".$redirect_uri."&prompt=consent"; header("Location: " . $authorize_url); return redirect($authorize_url); } function generate_refresh_token( $client_id, $client_secret, $grant_type, $refresh_token ) { $url = "https://accounts.zoho.com/oauth/v2/token"; $param = "refresh_token=".$refresh_token."&client_id=".$client_id."&client_secret=".$client_secret."&grant_type=".$grant_type; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $param); $result = curl_exec($ch); $err = curl_error($ch); curl_close($ch); if ($err) { echo $err; } else { $token_path = "token.json"; $response_data=json_decode($result,true); $tokens = array( 'access_token' => $response_data['access_token'], "created_at" => date('Y-m-d H:i:s') ); if ( !file_exists( dirname( $token_path ) ) ) { mkdir( dirname( $token_path ), 0777, true ); } file_put_contents( $token_path, json_encode( $tokens ) ); return $response_data['access_token']; } } }
Create config.php and add below code,
<?php return array ( 'userIdentifier' => 'jigna.vision14@gmail.com', 'refreshToken' => '1000.f6876feeb933ee200cd04c9aaf33c388.bca3e1eef1bd607e5b45f215dcb177d7', 'client_id' => '1000.IUDYQTEROO1024839NQXWAEK2C3Y5H', 'client_secret' => '3a0cc0d0a4fb74a808f6f4fdb75391645131765bbd', 'redirect_uri' => 'http://demoweb.com/sdk/function.php', 'token_persistence_path' => 'zcrm_oauthtokens.txt', 'scope' => 'ZohoCRM.modules.ALL', 'refresh_code' => '1000.76576b86fd625c202486cdade38692c8.6dc79d9d56a5c0eaf10cd925ea235538', );
Create function.php file and add below code,
<?php namespace zcrmsdk\oauth; require 'vendor/autoload.php'; use zcrmsdk\oauth\exception\ZohoOAuthException; use zcrmsdk\oauth\utility\OAuthLogger; use zcrmsdk\oauth\utility\ZohoOAuthConstants; use zcrmsdk\oauth\utility\ZohoOAuthHTTPConnector; use zcrmsdk\oauth\utility\ZohoOAuthTokens; use zcrmsdk\crm\setup\restclient\ZCRMRestClient; $configs = include("config.php"); $client_id = $configs['client_id']; $client_secret = $configs['client_secret']; $redirect_uri = $configs['redirect_uri']; $identifier = $configs['userIdentifier']; $scope = $configs['scope']; $token_persistence_path = $configs['token_persistence_path']; $refresh_code = $configs['refresh_code']; if ($_GET["code"]) { $access_token = generate_access_token( $refresh_code, $identifier ); } else { getAuthorizationCode(); } /* generate Grant code */function getAuthorizationCode() { global $authorize_url, $client_id, $scope, $redirect_uri; $authorize_url = "https://accounts.zoho.com/oauth/v2/auth?&scope=ZohoCRM.modules.ALL&client_id=".$client_id."&response_type=code&access_type=offline&redirect_uri=".$redirect_uri."&prompt=consent"; header("Location: " . $authorize_url); return redirect($authorize_url); } /* get access code */function generate_access_token( $refresh_code, $identifier ) { Global $client_id, $client_secret, $redirect_uri, $identifier, $token_persistence_path; $configuration = array( "client_id" => $client_id, "client_secret" => $client_secret, "redirect_uri" => $redirect_uri, "currentUserEmail" => $identifier, "token_persistence_path" => $token_persistence_path, ); ZCRMRestClient::initialize($configuration); $oAuthClient = ZohoOAuth::getClientInstance(); $refreshToken = $refresh_code; $userIdentifier = $identifier; $oAuthTokens = $oAuthClient->generateAccessTokenFromRefreshToken($refreshToken,$userIdentifier); $d = json_decode($oAuthTokens); }
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular