Back to Collection Items
require 'chilkat'
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
http = Chilkat::CkHttp.new()
req = Chilkat::CkHttpRequest.new()
jsonParam1 = Chilkat::CkJsonObject.new()
req.AddParam("code",jsonParam1.emit())
req.AddParam("grant_type","authorization_code")
req.AddHeader("Authorization","Basic {{encodedKeys}}")
# resp is a CkHttpResponse
resp = http.PostUrlEncoded("https://{{hostenv}}/oauth/token",req)
if (http.get_LastMethodSuccess() == false)
print http.lastErrorText() + "\n";
exit
end
print resp.get_StatusCode().to_s() + "\n";
print resp.bodyStr() + "\n";
Curl Command
curl -X POST
-H "Authorization: Basic {{encodedKeys}}"
--data-urlencode 'code={{codeFromUrl}}'
--data-urlencode 'grant_type=authorization_code'
https://{{hostenv}}/oauth/token
Postman Collection Item JSON
{
"name": "01 Authorize Code Grant Access Token",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"accessToken\", jsonData.access_token);"
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Basic {{encodedKeys}}"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "code",
"value": "{{codeFromUrl}}"
},
{
"key": "grant_type",
"value": "authorization_code"
}
]
},
"url": {
"raw": "https://{{hostenv}}/oauth/token",
"protocol": "https",
"host": [
"{{hostenv}}"
],
"path": [
"oauth",
"token"
]
}
},
"response": [
]
}