Chilkat Online Tools

PureBasic / Bond APIs / Get Auth Token

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkDtObj.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")
    CkHttp::ckSetRequestHeader(http,"Authorization","{{authorization}}")
    CkHttp::ckSetRequestHeader(http,"Identity","{{identity}}")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckQuickGetSb(http,"https://{{environment}}.bond.tech/api/v0/auth/key/{{identity}}",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    ; 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.i = CkDtObj::ckCreate()
    If date_created.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    date_updated.i = CkDtObj::ckCreate()
    If date_updated.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    date_revoked.i = CkDtObj::ckCreate()
    If date_revoked.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    date_expired.i = CkDtObj::ckCreate()
    If date_expired.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    identity.s = CkJsonObject::ckStringOf(jResp,"identity")
    key_name.s = CkJsonObject::ckStringOf(jResp,"key_name")
    role_id.s = CkJsonObject::ckStringOf(jResp,"role_id")
    role_name.s = CkJsonObject::ckStringOf(jResp,"role_name")
    org_id.s = CkJsonObject::ckStringOf(jResp,"org_id")
    grantor.s = CkJsonObject::ckStringOf(jResp,"grantor")
    grantee.s = CkJsonObject::ckStringOf(jResp,"grantee")
    CkJsonObject::ckDtOf(jResp,"date_created",0,date_created)
    CkJsonObject::ckDtOf(jResp,"date_updated",0,date_updated)
    CkJsonObject::ckDtOf(jResp,"date_revoked",0,date_revoked)
    CkJsonObject::ckDtOf(jResp,"date_expired",0,date_expired)
    status.s = CkJsonObject::ckStringOf(jResp,"status")
    call_count.i = CkJsonObject::ckIntOf(jResp,"call_count")
    last_call.s = CkJsonObject::ckStringOf(jResp,"last_call")
    last_auth.s = CkJsonObject::ckStringOf(jResp,"last_auth")
    last_used.s = CkJsonObject::ckStringOf(jResp,"last_used")
    last_method.s = CkJsonObject::ckStringOf(jResp,"last_method")
    last_route.s = CkJsonObject::ckStringOf(jResp,"last_route")


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)
    CkDtObj::ckDispose(date_created)
    CkDtObj::ckDispose(date_updated)
    CkDtObj::ckDispose(date_revoked)
    CkDtObj::ckDispose(date_expired)


    ProcedureReturn
EndProcedure

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}"
    }
  ]
}