question

sakuraime avatar image
0 Votes"
sakuraime asked SaurabhSharma-msft answered

Azure VM managed identify OAuthen token

I use Azure VM managed identity to access a Azure sql database . from a powershell .

I got the access token like in the following

 $response= Invoke-WebRequest -Uri 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fdatabase.windows.net%2F' -Headers @{Metadata="true"}
 $access_token = ($response.Content | ConvertFrom-Json).access_token


may I know what's the expiration of each time of the token is get ??? coz I found sometimes if I get too much at the same time , there will be error.

Thanks

windows-server-powershellazure-managed-identity
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SaurabhSharma-msft avatar image
0 Votes"
SaurabhSharma-msft answered

Hi @sakuraime,

You can find the VM managed token expiration time by looking at expires_on attribute of the response payload which is an epoch timestamp. (See screenshot below).
103161-image.png

Also, for VM Managed identity, I could see it is 24 hours.

Thanks
Saurabh


Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.


image.png (381.8 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.