-1

I am following below link:
https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-code-grant

Step 1 worked fine and I am able to receive Authorization Code
Step 2 Not working gives error "Could not resolve host: account-d.docusign.com%2Foauth%2Ftoken"

Running this on Apache server, php 7.3, using CURL.

$authcode = "";    
if(isset($_GET['code'])){    
    $authcode = $_GET['code'];    
}    

$headauth = base64_encode('bbc034da-a19f-48db-a841-25832e209a41:2f08bab1-2ccc-435f-a1f7-d43802b51255');    

$request_headers = array();    
$request_headers[] = 'Content-Type: application/x-www-form-urlencoded';    
$request_headers[] = 'Authorization: Basic '.$headauth;    

$ch = curl_init();    

$url = str_replace ( ' ', '%20', "https://account-d.docusign.com/oauth/token" );    

curl_setopt($ch, CURLOPT_URL,urlencode($url));    
curl_setopt($ch, CURLOPT_HEADER, 1);    
curl_setopt($ch, CURLOPT_POST, 1);    
curl_setopt($ch, CURLOPT_POSTFIELDS,"grant_type=authorization_code&code=".$authcode."&redirect_uri=http://192.168.2.56/testdocusign/test.php");  //Post Fields    
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);    
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  0);    
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);    

$server_output = curl_exec ($ch);    
if (curl_errno($ch)) {    
    $error_msg = curl_error($ch);    
    print_r($error_msg);    
}    

curl_close ($ch);    

print_r($server_output) ;    

I expect result something like below:

{    
    "access_token": "ISSUED_ACCESS_TOKEN",    
    "token_type": "Bearer",    
    "refresh_token": "ISSUED_REFRESH_TOKEN",    
    "expires_in": 28800    
}  

But my current error is :

Could not resolve host: account-d.docusign.com%2Foauth%2Ftoken

eibersji
  • 1,218
  • 4
  • 29
  • 52
Ankit
  • 3
  • 2
  • **[You should not switch off `CURLOPT_SSL_VERIFYHOST` or `CURLOPT_SSL_VERIFYPEER`](https://paragonie.com/blog/2017/10/certainty-automated-cacert-pem-management-for-php-software)**. It could be a security risk! [Here is how to get the certificate bundle if your server is missing one](https://stackoverflow.com/a/32095378/1839439) – Dharman Oct 11 '19 at 18:51
  • I was just experimenting with these 2 lines: curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); Even if I remove these 2 lines I get the same error. – Ankit Oct 14 '19 at 09:56

1 Answers1

0

As you can see the url is incorrect. you need to get the access code that you got from the first call you said worked ok and add it to the second call instead of the %2Foauth%2Ftoken part which is obviously just a placeholder for the token.

(edit: the issue was incorrect url encoding, that was the culprit)

Inbar Gazit
  • 12,566
  • 1
  • 16
  • 23
  • URL looks fine to me as I am following the steps from below link: `https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-code-grant` Below post url will be used: `https://account-d.docusign.com/oauth/token` I am passing the access code($authcode) as below: `curl_setopt($ch, CURLOPT_POSTFIELDS,"grant_type=authorization_code&code=".$authcode."&redirect_uri=http://192.168.2.56/testdocusign/test.php");` – Ankit Oct 11 '19 at 05:17
  • do you replace the parameter in the url with the token? – Inbar Gazit Oct 11 '19 at 14:09
  • This API is to get the token. I don't have token right now to pass in the url and there is no need to pass the token in the URL. Although I am passing other necessary details like authcode: curl_setopt($ch, CURLOPT_POSTFIELDS,"grant_type=authorization_code&code=".$authcode."&redirect_uri=http://192.168.2.56/testdocusign/test.php"); and Authorization Header $request_headers[] = 'Authorization: Basic '.$headauth; – Ankit Oct 14 '19 at 09:53
  • well, not sure what to tell you. account-d.docusign.com%2Foauth%2Ftoken is an invalid url. If you insist it's valid, then why do you get an error? – Inbar Gazit Oct 14 '19 at 16:51
  • what I recommend is that you check your url encoding. You somehow encoded the url in a way that's invalid. – Inbar Gazit Oct 14 '19 at 16:52
  • You were right the issue was with urlencode function. I removed it and everything worked perfect. Thanks a lot. – Ankit Oct 16 '19 at 05:28
  • would you mind marking the question as answered? thanks! – Inbar Gazit Oct 16 '19 at 15:30