Exception in authenticating
Hello,
I am using v4 of the PHP SDK.
My expectation is that a user would have to authenticate once. Once the user has stored the grant/refresh tokens on the website that will be querying the Zoho API, the user should not need to authenticate again.
However, my initial testing is proving difficult.
where I am asked to authenticate and allow access.
I am then forwarded to the redirect url with the `code` query string containing the grant token.
which gives me JSON data with a refresh token (along with the same grant token)
Now, when I use that refresh token in the PHP code, I get an exception.
class ZohoCrm
{
public static function init()
{
/*
* Create an instance of Logger Class that requires the following
* level -> Level of the log messages to be logged. Can be configured by typing Levels "::" and choose any level from the list displayed.
* filePath -> Absolute file path, where messages need to be logged.
*/
$logger = (new LogBuilder())
->level(Levels::INFO)
->filePath(__DIR__ . '/data/logs/zoho_php_sdk_log.log')
->build();
//Create an UserSignature instance that takes user Email as parameter
$user = new UserSignature("any@email.c");
/*
* Configure the environment
* which is of the pattern Domain::Environment
* Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter
* Available Environments: PRODUCTION(), DEVELOPER(), SANDBOX()
*/
/** @var Environment $environment */
$environment = EUDataCenter::PRODUCTION();
/*
* Create a Token instance
* clientId -> OAuth client id.
* clientSecret -> OAuth client secret.
* grantToken -> GRANT token.
* redirectURL -> OAuth redirect URL.
*/
//Create a Token instance
/** @var OAuthToken $token */
$token = (new OAuthBuilder())
->clientId('<CLIENT_ID>')
->clientSecret('<CLIENT_SECRET>')
->grantToken('<GRANT_TOKEN>')
->refreshToken('<REFRESH_TOKEN>')
->redirectURL('REDIRECT_URL)
->build();
/*
* TokenStore can be any of the following
* DB Persistence - Create an instance of DBStore
* File Persistence - Create an instance of FileStore
* Custom Persistence - Create an instance of CustomStore
*/
/*
* Create an instance of DBStore.
* host -> DataBase host name. Default value "localhost"
* databaseName -> DataBase name. Default value "zohooauth"
* userName -> DataBase user name. Default value "root"
* password -> DataBase password. Default value ""
* portNumber -> DataBase port number. Default value "3306"
* tableName -> DataBase table name. Default value "oauthtoken"
*/
//$tokenstore = (new DBBuilder())->build();
/** @var \com\zoho\api\authenticator\store\TokenStore $tokenstore */
$tokenstore = (new DBBuilder())
->host("db")
->databaseName('database')
->userName('database_user')
->password('')
->portNumber("3306")
// ->tableName("tableName")
->build();
// $tokenstore = new FileStore("absolute_file_path");
// $tokenstore = new CustomStore();
$autoRefreshFields = false;
$pickListValidation = false;
$connectionTimeout = 2;//The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
$timeout = 2;//The maximum number of seconds to allow cURL functions to execute.
$enableSSLVerification = false;
$sdkConfig = (new SDKConfigBuilder())->autoRefreshFields($autoRefreshFields)->pickListValidation($pickListValidation)->sslVerification($enableSSLVerification)->connectionTimeout($connectionTimeout)->timeout($timeout)->build();
$resourcePath = __DIR__ .'/data/';
//Create an instance of RequestProxy
// $requestProxy = (new ProxyBuilder())
// ->host("proxyHost")
// ->port("proxyPort")
// ->user("proxyUser")
// ->password("password")
// ->build();
/*
* Set the following in InitializeBuilder
* user -> UserSignature instance
* environment -> Environment instance
* token -> Token instance
* store -> TokenStore instance
* SDKConfig -> SDKConfig instance
* resourcePath -> resourcePath - A String
* logger -> Log instance (optional)
* requestProxy -> RequestProxy instance (optional)
*/
(new InitializeBuilder())
->user($user)
->environment($environment)
->token($token)
->store($tokenstore)
->SDKConfig($sdkConfig)
->resourcePath($resourcePath)
->logger($logger)
// ->requestProxy($requestProxy)
->initialize();
self::get_currencies();
}
protected static function get_currencies()
{
$currenciesOperations = new CurrenciesOperations();
$response = $currenciesOperations->getCurrencies();
// This causes an exception }
}