Chilkat Online Tools

C++ / DocuSign eSignature REST API / 02 JWT Access Token

Back to Collection Items

#include <CkHttp.h>
#include <CkHttpRequest.h>
#include <CkJsonObject.h>
#include <CkHttpResponse.h>

void ChilkatSample(void)
    {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http;
    bool success;

    CkHttpRequest req;

    CkJsonObject jsonParam1;
    req.AddParam("assertion",jsonParam1.emit());
    req.AddParam("grant_type","urn:ietf:params:oauth:grant-type:jwt-bearer");

    req.AddHeader("Authorization","Basic {{encodedKeys}}");

    CkHttpResponse *resp = http.PostUrlEncoded("https://{{hostenv}}/oauth/token",req);
    if (http.get_LastMethodSuccess() == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    std::cout << resp->get_StatusCode() << "\r\n";
    std::cout << resp->bodyStr() << "\r\n";
    delete resp;
    }

Curl Command

curl -X POST
	-H "Authorization: Basic {{encodedKeys}}"
	--data-urlencode 'assertion={{assertionHere}}'
	--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer'
https://{{hostenv}}/oauth/token

Postman Collection Item JSON

{
  "name": "02 JWT Access Token",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "postman.setEnvironmentVariable(\"accessToken\", jsonData.access_token);"
        ]
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "Basic {{encodedKeys}}"
      }
    ],
    "body": {
      "mode": "urlencoded",
      "urlencoded": [
        {
          "key": "assertion",
          "value": "{{assertionHere}}"
        },
        {
          "key": "grant_type",
          "value": "urn:ietf:params:oauth:grant-type:jwt-bearer"
        }
      ]
    },
    "url": {
      "raw": "https://{{hostenv}}/oauth/token",
      "protocol": "https",
      "host": [
        "{{hostenv}}"
      ],
      "path": [
        "oauth",
        "token"
      ]
    }
  },
  "response": [
  ]
}