Post commands are HTTP commands that are used to send data to servers and create or update resources. Using a Post command allows you to authenticate to the Genetec ClearID™ token service.
Below is a simple Microsoft PowerShell example of how to authenticate to the ClearID token service using a Post.
Once you receive the token, you can add it to the header of any REST API call.
Make sure to have at least one identity with the external ID 1234 if you want this sample to return data.
$client_id = "you client id from clearid"
$client_secret = "your client secret from clearid"
$clearid_accountid = "your accountid" #can be found in the uRL https://demo.clearid.io/{accountid}/
#Authenticating to ClearID Token endpoint
$demo_OAuth_Token_Endpoint = "https://sts-demo.clearid.io/connect/token"
$production_OAuth_Token_Endpoint = "https://sts-demo.clearid.io/connect/token"
$OAuthTokenEndpoint = $demo_OAuth_Token_Endpoint
$body = @{
client_id = $client_id
client_secret = $client_secret
grant_type = "client_credentials"
}
try { $tokenRequest = Invoke-WebRequest -Method Post -Uri $OAuthTokenEndpoint -ContentType "application/x-www-form-urlencoded" -Body $body -UseBasicParsing -ErrorAction Stop }
catch { Write-Host "Unable to obtain access token, aborting..."; return }
#The Token endpoint returns a JSON containing the bearer token
$token = ($tokenRequest.Content | ConvertFrom-Json).access_token
$authHeader = @{
'Content-Type'='application\json'
'Authorization'="Bearer $token"
}
#Calling a ClearID REST API with the bearer token in the header of the HTTP request
# Looking for an Identity that has the external ID "1234"
$external_id = "1234"
$encodedURLExternalid = [System.Web.HttpUtility]::UrlEncode($external_id)
$URL = "https://identityservice-demo.clearid.io/api/v2/accounts/" + $clearid_accountid + "/identities?externalid=" + $encodedURLExternalid;
try { $Identities_externalid = Invoke-WebRequest -Headers $AuthHeader -Uri $URL -UseBasicParsing }
catch { Write-Host "Unable to obtain access token, aborting..."; return }
#The Token endpoint returns a JSON containing the bearer token
$list_identities = $Identities_externalid.Content | ConvertFrom-Json