Chilkat Online Tools

unicodeC / Bond APIs / Get Auth Token

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkDtObjW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    HCkDtObjW date_created;
    HCkDtObjW date_updated;
    HCkDtObjW date_revoked;
    HCkDtObjW date_expired;
    const wchar_t *identity;
    const wchar_t *key_name;
    const wchar_t *role_id;
    const wchar_t *role_name;
    const wchar_t *org_id;
    const wchar_t *grantor;
    const wchar_t *grantee;
    const wchar_t *status;
    int call_count;
    const wchar_t *last_call;
    const wchar_t *last_auth;
    const wchar_t *last_used;
    const wchar_t *last_method;
    const wchar_t *last_route;

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

    http = CkHttpW_Create();

    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
    CkHttpW_SetRequestHeader(http,L"Authorization",L"{{authorization}}");
    CkHttpW_SetRequestHeader(http,L"Identity",L"{{identity}}");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://{{environment}}.bond.tech/api/v0/auth/key/{{identity}}",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpW_getLastStatus(http);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpW_lastHeader(http));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "identity": "a927213f-514c-49b3-a5a6-f9448bb57e9e",
    //   "key_name": "xyz_key",
    //   "role_id": "7e9d7292-2dd9-458b-9847-bc7fec065369",
    //   "role_name": "OS_FULL_ACCESS",
    //   "org_id": "073dff15-8bfe-4f00-9f55-c05ad0927cee",
    //   "grantor": "89e851fa-a7f4-4058-998c-4bd2d8b19b7a",
    //   "grantee": "ba272a5f-3f90-46da-a2fa-5d433629fcb2",
    //   "date_created": "2020-11-13 21:09:18.244428+00:00",
    //   "date_updated": "2020-11-20 19:35:29.180389+00:00",
    //   "date_revoked": "",
    //   "date_expired": "",
    //   "status": "active",
    //   "call_count": 197,
    //   "last_call": "2020-11-20 19:35:29.179258+00:00",
    //   "last_auth": "S",
    //   "last_used": "2020-11-20 19:35:29.179548+00:00",
    //   "last_method": "unknown",
    //   "last_route": "unknown"
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    date_created = CkDtObjW_Create();
    date_updated = CkDtObjW_Create();
    date_revoked = CkDtObjW_Create();
    date_expired = CkDtObjW_Create();

    identity = CkJsonObjectW_stringOf(jResp,L"identity");
    key_name = CkJsonObjectW_stringOf(jResp,L"key_name");
    role_id = CkJsonObjectW_stringOf(jResp,L"role_id");
    role_name = CkJsonObjectW_stringOf(jResp,L"role_name");
    org_id = CkJsonObjectW_stringOf(jResp,L"org_id");
    grantor = CkJsonObjectW_stringOf(jResp,L"grantor");
    grantee = CkJsonObjectW_stringOf(jResp,L"grantee");
    CkJsonObjectW_DtOf(jResp,L"date_created",FALSE,date_created);
    CkJsonObjectW_DtOf(jResp,L"date_updated",FALSE,date_updated);
    CkJsonObjectW_DtOf(jResp,L"date_revoked",FALSE,date_revoked);
    CkJsonObjectW_DtOf(jResp,L"date_expired",FALSE,date_expired);
    status = CkJsonObjectW_stringOf(jResp,L"status");
    call_count = CkJsonObjectW_IntOf(jResp,L"call_count");
    last_call = CkJsonObjectW_stringOf(jResp,L"last_call");
    last_auth = CkJsonObjectW_stringOf(jResp,L"last_auth");
    last_used = CkJsonObjectW_stringOf(jResp,L"last_used");
    last_method = CkJsonObjectW_stringOf(jResp,L"last_method");
    last_route = CkJsonObjectW_stringOf(jResp,L"last_route");


    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);
    CkDtObjW_Dispose(date_created);
    CkDtObjW_Dispose(date_updated);
    CkDtObjW_Dispose(date_revoked);
    CkDtObjW_Dispose(date_expired);

    }

Curl Command

curl -X GET
	-H "Content-Type: application/json"
	-H "Authorization: {{authorization}}"
	-H "Identity: {{identity}}"
https://{{environment}}.bond.tech/api/v0/auth/key/{{identity}}

Postman Collection Item JSON

{
  "name": "Get Auth Token",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "type": "text",
        "value": "application/json"
      },
      {
        "key": "Authorization",
        "type": "text",
        "value": "{{authorization}}"
      },
      {
        "key": "Identity",
        "type": "text",
        "value": "{{identity}}"
      }
    ],
    "url": {
      "raw": "https://{{environment}}.bond.tech/api/v0/auth/key/{{identity}}",
      "protocol": "https",
      "host": [
        "{{environment}}",
        "bond",
        "tech"
      ],
      "path": [
        "api",
        "v0",
        "auth",
        "key",
        "{{identity}}"
      ]
    },
    "description": "Add Card financial Core"
  },
  "response": [
    {
      "name": "example",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "type": "text",
            "value": "application/json"
          },
          {
            "key": "Authorization",
            "type": "text",
            "value": "{{Authorization}}"
          },
          {
            "key": "Identity",
            "type": "text",
            "value": "{{Identity}}"
          }
        ],
        "url": {
          "raw": "https://{{environment}}.bond.tech/api/v0/auth/key/a927213f-514c-49b3-a5a6-f9448bb57e9e",
          "protocol": "https",
          "host": [
            "{{environment}}",
            "bond",
            "tech"
          ],
          "path": [
            "api",
            "v0",
            "auth",
            "key",
            "a927213f-514c-49b3-a5a6-f9448bb57e9e"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Content-Length",
          "value": "691"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Server",
          "value": "gunicorn/19.9.0"
        },
        {
          "key": "Accept-Ranges",
          "value": "bytes"
        },
        {
          "key": "Date",
          "value": "Fri, 20 Nov 2020 19:35:29 GMT"
        },
        {
          "key": "Via",
          "value": "1.1 varnish"
        },
        {
          "key": "X-Served-By",
          "value": "cache-pao17424-PAO"
        },
        {
          "key": "X-Cache",
          "value": "MISS"
        },
        {
          "key": "X-Cache-Hits",
          "value": "0"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31557600"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"identity\": \"a927213f-514c-49b3-a5a6-f9448bb57e9e\",\n    \"key_name\": \"xyz_key\",\n    \"role_id\": \"7e9d7292-2dd9-458b-9847-bc7fec065369\",\n    \"role_name\": \"OS_FULL_ACCESS\",\n    \"org_id\": \"073dff15-8bfe-4f00-9f55-c05ad0927cee\",\n    \"grantor\": \"89e851fa-a7f4-4058-998c-4bd2d8b19b7a\",\n    \"grantee\": \"ba272a5f-3f90-46da-a2fa-5d433629fcb2\",\n    \"date_created\": \"2020-11-13 21:09:18.244428+00:00\",\n    \"date_updated\": \"2020-11-20 19:35:29.180389+00:00\",\n    \"date_revoked\": \"\",\n    \"date_expired\": \"\",\n    \"status\": \"active\",\n    \"call_count\": 197,\n    \"last_call\": \"2020-11-20 19:35:29.179258+00:00\",\n    \"last_auth\": \"S\",\n    \"last_used\": \"2020-11-20 19:35:29.179548+00:00\",\n    \"last_method\": \"unknown\",\n    \"last_route\": \"unknown\"\n}"
    }
  ]
}