Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Managed Identity - Calculate the refresh_in value based on expires_in #4062

Closed
gladjohn opened this issue Apr 7, 2023 · 1 comment · Fixed by #4068
Closed

Comments

@gladjohn
Copy link
Contributor

gladjohn commented Apr 7, 2023

Managed Identity Endpoints do not give us refresh_in. The plan is to calculate this in MSAL

A sample Managed Identity Token response from IMDS Endpoint is seen below,

HTTP/1.1 200 OK
Content-Type: application/json
{
  "access_token": "eyJ0eXAi...",
  "refresh_token": "",
  "expires_in": "3599",
  "expires_on": "1506484173",
  "not_before": "1506480273",
  "resource": "https://management.azure.com/",
  "token_type": "Bearer"
}

Compute refresh_in as 1/2 expires_in, but only if expires_in > 2h.

if expires_in > 2h 
   refresh_in =  expires_in * 0.50 
else 
      refresh_in = null;

Where:

  • expires_in: The lifetime of the access token in seconds.
  • buffer_time: The amount of time (in seconds) you want to subtract from the token lifetime to ensure that you refresh the token before it expires. This is typically a small value, such as 60 seconds, to avoid any chance of the token expiring before it can be refreshed.
  • refresh_in: The time (in seconds) after which you should refresh the access token to ensure that it remains valid.
    The value of 0.50 in the formula is a recommended value for the refresh time. This ensures that the token is refreshed before it expires while also minimizing the number of unnecessary refreshes.

For example, if the token lifetime is 3600 seconds (1 hour) and the buffer time is 60 seconds, then the refresh time would be:

expires_in = 7200 -> refresh_in  = 3600
expires_in = 3600 -> refresh_in = null
@gladjohn gladjohn self-assigned this Apr 7, 2023
@gladjohn gladjohn changed the title [Feature Request] Managed Identity - Calculate the refresh_in value [Feature Request] Managed Identity - Calculate the refresh_in value based on exires_in Apr 7, 2023
@gladjohn gladjohn added this to the 4.53.0 milestone Apr 12, 2023
@bgavrilMS
Copy link
Member

Please make sure this is documented in our MI implementation (API review).

@pmaytak pmaytak modified the milestones: 4.53.0, 4.54.0 Apr 14, 2023
@pmaytak pmaytak changed the title [Feature Request] Managed Identity - Calculate the refresh_in value based on exires_in [Feature Request] Managed Identity - Calculate the refresh_in value based on expires_in Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment