Table of Contents

Class TokenCacheNotificationArgs

Namespace
Microsoft.Identity.Client
Assembly
Microsoft.Identity.Client.dll

Contains parameters used by the MSAL call accessing the cache. See also ITokenCacheSerializer which contains methods to customize the cache serialization. For more details about the token cache see https://aka.ms/msal-net-web-token-cache

public sealed class TokenCacheNotificationArgs
Inheritance
TokenCacheNotificationArgs
Inherited Members

Constructors

TokenCacheNotificationArgs(ITokenCacheSerializer, string, IAccount, bool, bool, string, bool, DateTimeOffset?, CancellationToken)

This constructor is for test purposes only. It allows apps to unit test their MSAL token cache implementation code.

public TokenCacheNotificationArgs(ITokenCacheSerializer tokenCache, string clientId, IAccount account, bool hasStateChanged, bool isApplicationCache, string suggestedCacheKey, bool hasTokens, DateTimeOffset? suggestedCacheExpiry, CancellationToken cancellationToken)

Parameters

tokenCache ITokenCacheSerializer
clientId string
account IAccount
hasStateChanged bool
isApplicationCache bool
suggestedCacheKey string
hasTokens bool
suggestedCacheExpiry DateTimeOffset?
cancellationToken CancellationToken

TokenCacheNotificationArgs(ITokenCacheSerializer, string, IAccount, bool, bool, string, bool, DateTimeOffset?, CancellationToken, Guid)

This constructor is for test purposes only. It allows apps to unit test their MSAL token cache implementation code.

public TokenCacheNotificationArgs(ITokenCacheSerializer tokenCache, string clientId, IAccount account, bool hasStateChanged, bool isApplicationCache, string suggestedCacheKey, bool hasTokens, DateTimeOffset? suggestedCacheExpiry, CancellationToken cancellationToken, Guid correlationId)

Parameters

tokenCache ITokenCacheSerializer
clientId string
account IAccount
hasStateChanged bool
isApplicationCache bool
suggestedCacheKey string
hasTokens bool
suggestedCacheExpiry DateTimeOffset?
cancellationToken CancellationToken
correlationId Guid

TokenCacheNotificationArgs(ITokenCacheSerializer, string, IAccount, bool, bool, string, bool, DateTimeOffset?, CancellationToken, Guid, IEnumerable<string>, string)

This constructor is for test purposes only. It allows apps to unit test their MSAL token cache implementation code.

public TokenCacheNotificationArgs(ITokenCacheSerializer tokenCache, string clientId, IAccount account, bool hasStateChanged, bool isApplicationCache, string suggestedCacheKey, bool hasTokens, DateTimeOffset? suggestedCacheExpiry, CancellationToken cancellationToken, Guid correlationId, IEnumerable<string> requestScopes, string requestTenantId)

Parameters

tokenCache ITokenCacheSerializer
clientId string
account IAccount
hasStateChanged bool
isApplicationCache bool
suggestedCacheKey string
hasTokens bool
suggestedCacheExpiry DateTimeOffset?
cancellationToken CancellationToken
correlationId Guid
requestScopes IEnumerable<string>
requestTenantId string

TokenCacheNotificationArgs(ITokenCacheSerializer, string, IAccount, bool, bool, string, bool, DateTimeOffset?, CancellationToken, Guid, IEnumerable<string>, string, IIdentityLogger, bool, TelemetryData)

This constructor is for test purposes only. It allows apps to unit test their MSAL token cache implementation code.

public TokenCacheNotificationArgs(ITokenCacheSerializer tokenCache, string clientId, IAccount account, bool hasStateChanged, bool isApplicationCache, string suggestedCacheKey, bool hasTokens, DateTimeOffset? suggestedCacheExpiry, CancellationToken cancellationToken, Guid correlationId, IEnumerable<string> requestScopes, string requestTenantId, IIdentityLogger identityLogger, bool piiLoggingEnabled, TelemetryData telemetryData = null)

Parameters

tokenCache ITokenCacheSerializer
clientId string
account IAccount
hasStateChanged bool
isApplicationCache bool
suggestedCacheKey string
hasTokens bool
suggestedCacheExpiry DateTimeOffset?
cancellationToken CancellationToken
correlationId Guid
requestScopes IEnumerable<string>
requestTenantId string
identityLogger IIdentityLogger
piiLoggingEnabled bool
telemetryData TelemetryData

Properties

Account

Gets the account involved in the cache transaction.

public IAccount Account { get; }

Property Value

IAccount

CancellationToken

The cancellation token that was passed to AcquireToken* flow via ExecuteAsync(CancellationToken). Can be passed along to the custom token cache implementation.

public CancellationToken CancellationToken { get; }

Property Value

CancellationToken

ClientId

Gets the ClientId (application ID) of the application involved in the cache transaction

public string ClientId { get; }

Property Value

string

CorrelationId

The correlation id associated with the request. See WithCorrelationId(Guid)

public Guid CorrelationId { get; }

Property Value

Guid

HasStateChanged

Indicates whether the state of the cache has changed, for example when tokens are being added or removed. Not all cache operations modify the state of the cache.

public bool HasStateChanged { get; }

Property Value

bool

HasTokens

Is true when at least one non-expired access token exists in the cache.

public bool HasTokens { get; }

Property Value

bool

Remarks

If this flag is false in the OnAfterAccessAsync notification - the node can be deleted from the underlying storage (e.g. IDistributedCache). MSAL takes into consideration access tokens expiration when computing this flag. Use in conjunction with SuggestedCacheExpiry. If a refresh token exists in the cache, this property will always be true.

IdentityLogger

Identity Logger provided at the time of application creation Via WithLogging(IIdentityLogger, bool)/> Calling the log function will automatically add MSAL formatting to the message. For details see https://aka.ms/msal-net-logging

public IIdentityLogger IdentityLogger { get; }

Property Value

IIdentityLogger

IsApplicationCache

Indicates whether the cache change occurred in the UserTokenCache or in the AppTokenCache.

public bool IsApplicationCache { get; }

Property Value

bool

Remarks

The Application Cache is used in Client Credential grant, which is not available on all platforms. See https://aka.ms/msal-net-app-cache-serialization for details.

PiiLoggingEnabled

Boolean used to determine if Personally Identifiable Information (PII) logging is enabled.

public bool PiiLoggingEnabled { get; }

Property Value

bool

RequestScopes

Scopes specified in the AcquireToken* method.

public IEnumerable<string> RequestScopes { get; }

Property Value

IEnumerable<string>

Remarks

Note that Azure Active Directory may return more scopes than requested, however this property will only contain the scopes requested.

RequestTenantId

Tenant Id specified in the AcquireToken* method, if any.

public string RequestTenantId { get; }

Property Value

string

Remarks

Note that if "common" or "organizations" is specified, Azure Active Directory discovers the host tenant for the user, and the tokens are associated with it. This property is not impacted.

SuggestedCacheExpiry

Suggested value of the expiry, to help determining the cache eviction time. This value is only set on the

OnAfterAccess
delegate, on a cache write operation (that is when
args.HasStateChanged
is
true
) and when the cache node contains only access tokens.
In all other cases it's
null
.
public DateTimeOffset? SuggestedCacheExpiry { get; }

Property Value

DateTimeOffset?

SuggestedCacheKey

A suggested token cache key, which can be used with general purpose storage mechanisms that allow storing key-value pairs and key based retrieval. Useful in applications that store one token cache per user, the recommended pattern for web apps.

The value is:

  • homeAccountId for AcquireTokenSilent, GetAccount(homeAccountId), RemoveAccount and when writing tokens on confidential client calls
  • "{clientId}__AppTokenCache" for AcquireTokenForClient
  • "{clientId}_{tenantId}_AppTokenCache" for AcquireTokenForClient when using a tenant specific authority
  • the hash of the original token for AcquireTokenOnBehalfOf
public string SuggestedCacheKey { get; }

Property Value

string

TelemetryData

Cache Details contains the details of L1/ L2 cache for telemetry logging.

public TelemetryData TelemetryData { get; }

Property Value

TelemetryData

TokenCache

Gets the ITokenCacheSerializer involved in the transaction

public ITokenCacheSerializer TokenCache { get; }

Property Value

ITokenCacheSerializer

Remarks

objects implement this interface.