Chilkat Online Tools

PureBasic / Commercetools / Token Introspection

Back to Collection Items

IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.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::setCkBasicAuth(http, 1)
    CkHttp::setCkLogin(http, "username")
    CkHttp::setCkPassword(http, "password")

    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")

    resp.i = CkHttp::ckQuickRequest(http,"POST","https://domain.com/oauth/introspect?token={{ctp_access_token}}")
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)


    ProcedureReturn
EndProcedure

Curl Command

curl -X POST
	-u 'username:password'
	-H "Content-Type: application/json"
https://domain.com/oauth/introspect?token={{ctp_access_token}}

Postman Collection Item JSON

{
  "name": "Token Introspection",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "tests[\"Status code is 200\"] = responseCode.code === 200;"
        ]
      }
    }
  ],
  "request": {
    "auth": {
      "type": "basic",
      "basic": {
        "username": "{{client_id}}",
        "password": "{{client_secret}}"
      }
    },
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": ""
    },
    "url": {
      "raw": "{{auth_url}}/oauth/introspect?token={{ctp_access_token}}",
      "host": [
        "{{auth_url}}"
      ],
      "path": [
        "oauth",
        "introspect"
      ],
      "query": [
        {
          "key": "token",
          "value": "{{ctp_access_token}}",
          "equals": true
        }
      ]
    },
    "description": "Token introspection allows to determine the active state of an OAuth 2.0 access token and to determine meta-information about this accces token, such as the `scope`."
  },
  "response": [
  ]
}