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.

`TokenCacheNotificationArgs.Account` is null when read from cache

See original GitHub issue

I noticed that the first time the token is read from the cache it changes the HasTokens but does not assign the Account to the TokenCacheNotificationArgs in the OnAfterAccessAsync method. Only after token is accessed with AcquireTokenInLongRunningProcess is it set.

Which version of MSAL.NET are you using? 4.40.0

Platform ALL

What authentication flow has the issue?

  • Desktop / Mobile
    • Interactive
    • Integrated Windows Authentication
    • Username Password
    • Device code flow (browserless)
  • Web app
    • Authorization code
    • On-Behalf-Of
  • Daemon app
    • Service to Service calls

Is this a new or existing app? a. The app is in production, and I have upgraded to a new version of MSAL.

Expected behavior TokenCacheNotificationArgs.Account should be set.

Actual behavior TokenCacheNotificationArgs.Account is null

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

gabrigiunchicommented, May 30, 2023

Thanks for the explanation, now it’s more clear! I did found a workaround for my problem so we can close this issue. Thanks everyone! 😃

bgavrilMScommented, May 24, 2023

@pmaytak - can you please comment on @gabrigiunchi 's objection?

AcquireTokenSilent is aimed at web app scenario, not web api. It is scoped by the account itself, i.e. the user projection in a tenant (the user for short). Web API is session based, not user based. AcquireTokenSilent isn’t to be used with web api. For backwards compat purposes, AcquireTokenSilent will never find a refresh token and will throw a UiRequiredException error, which is part of the contract of AcquireTokenSilent.

Read more comments on GitHub >

github_iconTop Results From Across the Web

`TokenCache.SerializeAdalV3` returns `null` even with a ...
Git Credential Manager wants to move to MSAL, and part of that means we need to be able to read and write to...
Read more >
HttpContext.Current is null on TokenCache.BeforeAccess
I got it working. You have to pass the HttpContextBase for creating your session cache object. HttpContext. Current becomes null as it executes ......
Read more >
TokenCacheNotificationArgs Class (Microsoft.Identity.Client)
It allows apps to unit test their MSAL token cache implementation code. Properties. Account. Gets the account involved in the cache transaction.
Read more >
NullUserCache (Spring Security 4.0.4.RELEASE API)
getUsername() used to place the user in the cache; Returns: the populated UserDetails or null if the user could not be found or...
Read more >
Azure AD v2 and MSAL from a developer's point of view
So for example, let's say we want to read the user's calendar events ... ClientSecret), userTokenCache, null); //Get access token (and Id ...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found