SQL Server / Bond APIs / Get Auth Token
Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', '{{authorization}}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Identity', '{{identity}}'
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://{{environment}}.bond.tech/api/v0/auth/key/{{identity}}', @sbResponseBody
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
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
DECLARE @date_created int
-- Use "Chilkat_9_5_0.DtObj" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.DtObj', @date_created OUT
DECLARE @date_updated int
-- Use "Chilkat_9_5_0.DtObj" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.DtObj', @date_updated OUT
DECLARE @date_revoked int
-- Use "Chilkat_9_5_0.DtObj" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.DtObj', @date_revoked OUT
DECLARE @date_expired int
-- Use "Chilkat_9_5_0.DtObj" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.DtObj', @date_expired OUT
DECLARE @identity nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @identity OUT, 'identity'
DECLARE @key_name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @key_name OUT, 'key_name'
DECLARE @role_id nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @role_id OUT, 'role_id'
DECLARE @role_name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @role_name OUT, 'role_name'
DECLARE @org_id nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @org_id OUT, 'org_id'
DECLARE @grantor nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @grantor OUT, 'grantor'
DECLARE @grantee nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @grantee OUT, 'grantee'
EXEC sp_OAMethod @jResp, 'DtOf', @success OUT, 'date_created', 0, @date_created
EXEC sp_OAMethod @jResp, 'DtOf', @success OUT, 'date_updated', 0, @date_updated
EXEC sp_OAMethod @jResp, 'DtOf', @success OUT, 'date_revoked', 0, @date_revoked
EXEC sp_OAMethod @jResp, 'DtOf', @success OUT, 'date_expired', 0, @date_expired
DECLARE @status nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'status'
DECLARE @call_count int
EXEC sp_OAMethod @jResp, 'IntOf', @call_count OUT, 'call_count'
DECLARE @last_call nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @last_call OUT, 'last_call'
DECLARE @last_auth nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @last_auth OUT, 'last_auth'
DECLARE @last_used nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @last_used OUT, 'last_used'
DECLARE @last_method nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @last_method OUT, 'last_method'
DECLARE @last_route nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @last_route OUT, 'last_route'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
EXEC @hr = sp_OADestroy @date_created
EXEC @hr = sp_OADestroy @date_updated
EXEC @hr = sp_OADestroy @date_revoked
EXEC @hr = sp_OADestroy @date_expired
END
GO
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}"
}
]
}