<?php

$tokenUrl = "https://trms-api.azurewebsites.net/api/token";


$tenantId = 'EXT-B006';
$tenantSecret = '2Zs(Q@9B6V';


$data = [
    "grant_type" => "client_credentials",
    "tenant_id" => $tenantId,
    "tenant_secret" => $tenantSecret,
];


$headers = [
    "Content-Type: application/json",
];


$ch = curl_init($tokenUrl);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

if ($httpStatus == 200) {
    
    $response_data = json_decode($response, true);
    $access_token = $response_data["access_token"];
    echo "Access Token: " . $access_token;
} else {
    echo "Authentication error. Status code: " . $httpStatus;
    echo "Response: " . $response;
}
?>