Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkHttpRequestW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkHttpRequestW req;
HCkJsonObjectW jsonParam1;
HCkHttpResponseW resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
req = CkHttpRequestW_Create();
jsonParam1 = CkJsonObjectW_Create();
CkHttpRequestW_AddParam(req,L"assertion",CkJsonObjectW_emit(jsonParam1));
CkHttpRequestW_AddParam(req,L"grant_type",L"urn:ietf:params:oauth:grant-type:jwt-bearer");
CkHttpRequestW_AddHeader(req,L"Authorization",L"Basic {{encodedKeys}}");
resp = CkHttpW_PostUrlEncoded(http,L"https://{{hostenv}}/oauth/token",req);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkHttpRequestW_Dispose(req);
CkJsonObjectW_Dispose(jsonParam1);
return;
}
wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkHttpRequestW_Dispose(req);
CkJsonObjectW_Dispose(jsonParam1);
}
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);",
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"refreshToken\", jsonData.refresh_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": [
]
}