question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ITokenAcquisition token refresh and expiration

See original GitHub issue

Documentation Related To Component:

https://docs.microsoft.com/en-us/dotnet/api/microsoft.identity.web.itokenacquisition.getaccesstokenforappasync?view=azure-dotnet-preview https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-web-app-call-api-app-configuration?tabs=aspnetcore https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-web-app-call-api-acquire-token?tabs=aspnetcore https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-web-app-call-api-call-api?tabs=aspnetcore

Please check those that apply

  • typo
  • [x ] documentation doesn’t exist
  • [x ] documentation needs clarification
  • error(s) in example
  • [ x] needs example

Description Of The Issue

I’m currently injecting ITokenAcquisition and invoking GetAccessTokenForAppAsync in order to attain an access token from Azure AD.

I’ve wired it up using AddInMemoryTokenCaches. This is my code from Startup.cs:

services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(Configuration)
    .EnableTokenAcquisitionToCallDownstreamApi(new[] { Configuration["scopes"] })
    .AddInMemoryTokenCaches();

My question is does the implementation of ITokenAcquisition handle getting a refresh token when a currently cached token is nearing expiration? Aka, do I have to explicitly manage this in my code? If so, where is a good sample/docs of how to do that?

Also, if ITokenAcquisition does not handle token refresh based on expiration, will using IDownstreamWebApi handle it?

An example of where documentation is clear is when I used IdentityModel as my OIDC/OAuth2.0 library against Auth0 as the IdentityProvider.

On the Overview page, it clearly states (before diving into specifics or implementation) what you can expect to get out of using the library:

  • automatic refresh of expired access tokens
  • refresh token revocation
  • token lifetime automation for HttpClient

Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jmprieurcommented, Feb 9, 2021

@mgmccarthy yes, Microsoft.Identity.Web (whether you use ITokenAcquisition , IDownstreamApi or even GraphServiceClient) takes care of all this. It leverages MSAL.NET . See https://docs.microsoft.com/azure/active-directory/develop/msal-overview which provides the value of the MSAL libraries.

We’ll make sure we are explicit about that cc: @mmacy

1reaction
jmprieurcommented, Feb 9, 2021

@mgmccarthy : no need to recreate. I just moved it to the Microsoft.Identity.Web repo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ITokenAcquisition.GetAuthenticationResultForUserAsync ...
Below userAuthenticationResult should contain a non-expired AccessToken, and it should handle the token refresh within the method.
Read more >
ITokenAcquisition token refresh and expiration functionality
My question is does the implementation of ITokenAcquisition handle getting a refresh token when a currently cached token is nearing expiration?
Read more >
Using Refresh Tokens in ASP.NET Core Authentication
When access tokens expire, we can use refresh tokens to get a new access token from the authentication component. The lifetime of a...
Read more >
How to renew Jwt Access tokens using refresh tokens
But issue is this Jwt token is getting expired after certain time like 90 minutes in my app I think and API returns...
Read more >
Refresh tokens in the Microsoft identity platform
Refresh tokens have a longer lifetime than access tokens. The default lifetime for the refresh tokens is 24 hours for single page apps...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found