Chilkat Online Tools

delphiDll / Bond APIs / Get Auth Token

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
date_created: HCkDtObj;
date_updated: HCkDtObj;
date_revoked: HCkDtObj;
date_expired: HCkDtObj;
identity: PWideChar;
key_name: PWideChar;
role_id: PWideChar;
role_name: PWideChar;
org_id: PWideChar;
grantor: PWideChar;
grantee: PWideChar;
status: PWideChar;
call_count: Integer;
last_call: PWideChar;
last_auth: PWideChar;
last_used: PWideChar;
last_method: PWideChar;
last_route: PWideChar;

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

http := CkHttp_Create();

CkHttp_SetRequestHeader(http,'Content-Type','application/json');
CkHttp_SetRequestHeader(http,'Authorization','{{authorization}}');
CkHttp_SetRequestHeader(http,'Identity','{{identity}}');

sbResponseBody := CkStringBuilder_Create();
success := CkHttp_QuickGetSb(http,'https://{{environment}}.bond.tech/api/v0/auth/key/{{identity}}',sbResponseBody);
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttp_getLastStatus(http);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttp__lastHeader(http));
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

// 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

date_created := CkDtObj_Create();
date_updated := CkDtObj_Create();
date_revoked := CkDtObj_Create();
date_expired := CkDtObj_Create();

identity := CkJsonObject__stringOf(jResp,'identity');
key_name := CkJsonObject__stringOf(jResp,'key_name');
role_id := CkJsonObject__stringOf(jResp,'role_id');
role_name := CkJsonObject__stringOf(jResp,'role_name');
org_id := CkJsonObject__stringOf(jResp,'org_id');
grantor := CkJsonObject__stringOf(jResp,'grantor');
grantee := CkJsonObject__stringOf(jResp,'grantee');
CkJsonObject_DtOf(jResp,'date_created',False,date_created);
CkJsonObject_DtOf(jResp,'date_updated',False,date_updated);
CkJsonObject_DtOf(jResp,'date_revoked',False,date_revoked);
CkJsonObject_DtOf(jResp,'date_expired',False,date_expired);
status := CkJsonObject__stringOf(jResp,'status');
call_count := CkJsonObject_IntOf(jResp,'call_count');
last_call := CkJsonObject__stringOf(jResp,'last_call');
last_auth := CkJsonObject__stringOf(jResp,'last_auth');
last_used := CkJsonObject__stringOf(jResp,'last_used');
last_method := CkJsonObject__stringOf(jResp,'last_method');
last_route := CkJsonObject__stringOf(jResp,'last_route');

CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
CkDtObj_Dispose(date_created);
CkDtObj_Dispose(date_updated);
CkDtObj_Dispose(date_revoked);
CkDtObj_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}"
    }
  ]
}