docusign / docusign-esign-php-client

The Official Docusign PHP Client Library used to interact with the eSign REST API. Send, sign, and approve documents using this client.
https://www.docusign.com/devcenter
MIT License
198 stars 123 forks source link

Expected a refresh token method #121

Closed ReyazBeigh closed 3 years ago

ReyazBeigh commented 3 years ago

Hi Team,

was expecting a method to get token from refresh_token and didn't find one. I have added a method to ApiClient locally and that worked for me. Here is the definition

docusign-php-client/src/Client/ApiClient.php

public function refreshAccessToken($client_id = null, $client_secret = null, $code = null) { if (!$client_id) { throw new \InvalidArgumentException('Missing the required parameter $client_id when calling refreshAccessToken'); } if (!$client_secret || !$code) { throw new \InvalidArgumentException('Missing the required parameter $client_secret when calling refreshAccessToken'); } if (!$code) { throw new \InvalidArgumentException('Missing the required parameter $code when calling refreshAccessToken'); } $resourcePath = "/oauth/token"; $queryParams = []; $integrator_and_secret_key = "Basic " . utf8_decode(base64_encode("{$client_id}:{$client_secret}")); $headers = [ "Authorization" => $integrator_and_secret_key, "Content-Type" => "application/x-www-form-urlencoded", ]; $postData = [ "grant_type" => "refresh_token", "refresh_token" => $code, ]; list($response, $statusCode, $httpHeader) = $this->callApi($resourcePath, self::$POST, $queryParams, $postData, $headers, null, null, true); if (isset($response->access_token)) { $this->config->addDefaultHeader("Authorization", "{$response->token_type} {$response->access_token}"); } return [$this->getSerializer()->deserialize($response, '\DocuSign\eSign\Client\Auth\OAuthToken', $httpHeader), $statusCode, $httpHeader]; }

LarryKlugerDS commented 3 years ago

Thank you!

In addition, some PHP OAuth client libraries include support for refreshing tokens.

dbbrahmbhatt commented 3 years ago

Refresh token is added in v5.7.0