# Copy this code and save it to a file called authentication_example.ps1
# Replace placeholders below and run the command: .\authentication_example.ps1
# User-Agent is set explicitly so default library agents are not rejected by the gateway.
$ClientId = "REPLACE-ME-WITH-CLIENT-ID"
$ClientSecret = "REPLACE-ME-WITH-CLIENT-SECRET"
$OcpApimSubscriptionKey = "REPLACE-ME-WITH-SUBSCRIPTION-KEY"
$Scope = "REPLACE-ME-WITH-SCOPE"
$OrganizationNumber = "REPLACE-ME-WITH-ORGANIZATION-NUMBER"
Write-Host "Requesting access token from identity provider"
try {
$tokenResponse = Invoke-RestMethod -Uri https://id.talenom.com/api/b2b/oauth2/v1.0/token `
-ContentType application/x-www-form-urlencoded -Method POST `
-UserAgent "Easor-API-Client/1.0" -TimeoutSec 30 `
-Body "grant_type=client_credentials&client_id=$ClientId&client_secret=$ClientSecret&scope=$Scope"
} catch {
Write-Host "Token request failed:" $_.Exception.Message
if ($_.Exception.Response) {
Write-Host "HTTP status:" ([int]$_.Exception.Response.StatusCode)
}
throw
}
$access_token = $tokenResponse.access_token
Write-Host "This is your access token: $access_token"
# Call organization-api and get basic organization information for the organization assigned in the parameters.
$ApiUrl = "https://apim.talenom.com/organization/v1/organization-info/$OrganizationNumber"
$Headers = @{
Authorization = "Bearer $access_token"
"Content-Type" = "application/json"
"Ocp-Apim-Subscription-Key" = $OcpApimSubscriptionKey
"User-Agent" = "Easor-API-Client/1.0"
}
try {
Invoke-RestMethod -Uri $ApiUrl -Method GET -Headers $Headers -TimeoutSec 30
} catch {
Write-Host "API request failed:" $_.Exception.Message
if ($_.Exception.Response) {
Write-Host "HTTP status:" ([int]$_.Exception.Response.StatusCode)
}
throw
}