Laravel

Docusign refresh token – increase access token life span

In this blog, we will see how we can increase access token life span by DocuSign refresh token in laravel, as you see by default access token life span is 8 hours and after that again you need the access token in order to call DocuSign API.

But by using the DocuSign refresh token we can again create the access token by which we call the API’s.

To call the refresh token API , remember you already have the refresh token which you get during the auth, if you don’t have the refresh token then please refer to this link.

If you have the refresh token then use the below code to get your new access token.

$client_id = env('DOCUSIGN_CLIENT_ID');
        $client_secret = env('DOCUSIGN_CLIENT_SECRET');

        $integrator_and_secret_key = "Basic " . utf8_decode(base64_encode("{$client_id}:{$client_secret}"));

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, 'https://account-d.docusign.com/oauth/token');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        $post = array(
            'grant_type' => 'refresh_token',
            'refresh_token' => Option::get_option('docusign_refresh_code'),
        );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

        $headers = array();
        $headers[] = 'Cache-Control: no-cache';
        $headers[] = "authorization: $integrator_and_secret_key";
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $result = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        }
        curl_close($ch);
        $decodedData = json_decode($result);

I think the above code will help you to get the access token.

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button