azure-docs icon indicating copy to clipboard operation
azure-docs copied to clipboard

Access token expiration

Open schwichti opened this issue 2 years ago • 1 comments

More information on access token expiration would be desirable. I had the following questions: When a new access token is issued ( it seems is not issued when you call the endpoint) As far as I understand I am supposed to implement a retry logic in my application so that it gets a new token when it got a connection failure (because the token is expired). What do I need to do to prevent retries? Can I get a new access token before the old one is expired. If yes, how can I do this and what is the time span between the tokens.


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

schwichti avatar Jun 02 '23 13:06 schwichti

@schwichti Thanks for your feedback! We will investigate and update as appropriate.

SaibabaBalapur-MSFT avatar Jun 02 '23 18:06 SaibabaBalapur-MSFT

@schwichti Thank you for your question. When a new access token is issued, it is typically done when the previous token has expired. The expiration time of the access token is set by the Azure AD service and can be configured by the administrator. The default expiration time for an access token is 1 hour.

To prevent retries, you can implement a retry logic in your application that checks if the access token is still valid before making a request. If the access token is expired, your application can request a new access token before making the request. You can get a new access token before the old one is expired by using the refresh token. The refresh token is a long-lived token that can be used to obtain a new access token without requiring the user to sign in again.

To use the refresh token, you can make a request to the Azure AD token endpoint with the refresh token and the client ID and client secret of your application. The response will include a new access token and a new refresh token. The time span between the tokens depends on the expiration time set by the Azure AD service.

ManoharLakkoju-MSFT avatar Jun 05 '23 06:06 ManoharLakkoju-MSFT

@ManoharLakkoju-MSFT thanks for the quick reply. The document says that the refresh token is "not used by managed identities for Azure resources." It seems that the access token I got from http://169.254.169.254/metadata/identity/oauth2/token are valid 24h.

schwichti avatar Jun 05 '23 10:06 schwichti

When a new access token is issued, it is typically done when the previous token has expired.

does this imply that there can be a short period where the old access token has expired and the new access token has not been issued yet?

schwichti avatar Jun 05 '23 10:06 schwichti

@schwichti I'm going to assign this to the document author so they can take a look at it accordingly

@barclayn Can you please check and add your comments on this doc update request as applicable.

ManoharLakkoju-MSFT avatar Jun 05 '23 11:06 ManoharLakkoju-MSFT

@schwichti thank you for reaching out. I have created a work item to track internally and update the article with additional detail. In the meantime, if you still have questions please contact Microsoft support. #please-close

barclayn avatar Mar 25 '24 14:03 barclayn