Azure Web Apps
Azure Web Apps
Determine the slot in which we're running
Via incoming HTTP header
<h1>Server <?php echo $_SERVER['HTTP_WAS_DEFAULT_HOSTNAME']; ?></h1>Via system-assigned managed identity
Fetching a managed-identity access_token from PHP in an Azure Web App for Linux
access_token from PHP in an Azure Web App for Linux<?php
$resource = 'https://storage.azure.com/';
$endpoint = $_ENV["IDENTITY_ENDPOINT"];
$params = array('api-version' => '2019-08-01', 'resource' => $resource);
$url = $endpoint . '?' . http_build_query($params);
$headers = array(
'Metadata: true',
'X-IDENTITY-HEADER: ' . $_ENV['IDENTITY_HEADER']
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close ($ch);
$response_json = json_decode($response);
$access_token = $response_json->{'access_token'};
?>
<a href="https://jwt.ms/#access_token=<?php echo $access_token; ?>" target="_blank">
See the JWT in https://jwt.ms
</a>Last updated