TokenCache Class

Definition

Token cache storing access and refresh tokens for accounts This class is used in the constructors of PublicClientApplication and ConfidentialClientApplication. In the case of ConfidentialClientApplication, two instances are used, one for the user token cache, and one for the application token cache (in the case of applications using the client credential flows).

public sealed class TokenCache
type TokenCache = class
    interface ITokenCache
    interface ITokenCacheSerializer
Public NotInheritable Class TokenCache
Inheritance
TokenCache
Implements

Constructors

TokenCache()
Obsolete.

Constructor of a token cache. This constructor is left for compatibility with MSAL 2.x. The recommended way to get a cache is by using UserTokenCache and IConfidentialClientApplication.AppTokenCache once the app is created.

Methods

SetAfterAccess(TokenCacheCallback)

Sets a delegate to be notified after any library method accesses the cache. This gives an option to the delegate to serialize a cache entry for the application and accounts specified in the TokenCacheNotificationArgs. See https://aka.ms/msal-net-token-cache-serialization

SetAfterAccessAsync(Func<TokenCacheNotificationArgs,Task>)
SetBeforeAccess(TokenCacheCallback)

Sets a delegate to be notified before any library method accesses the cache. This gives an option to the delegate to deserialize a cache entry for the application and accounts specified in the TokenCacheNotificationArgs. See https://aka.ms/msal-net-token-cache-serialization

SetBeforeAccessAsync(Func<TokenCacheNotificationArgs,Task>)
SetBeforeWrite(TokenCacheCallback)

Sets a delegate called before any library method writes to the cache. This gives an option to the delegate to reload the cache state from a row in database and lock that row. That database row can then be unlocked in the delegate registered with SetAfterAccess(TokenCacheCallback)

SetBeforeWriteAsync(Func<TokenCacheNotificationArgs,Task>)
SetIosKeychainSecurityGroup(String)

Sets the security group to be used with the iOS Keychain. This function should not be used by external customers. It will be removed in a future version of MSAL.

Explicit Interface Implementations

ITokenCacheSerializer.DeserializeAdalV3(Byte[])
ITokenCacheSerializer.DeserializeMsalV2(Byte[])
ITokenCacheSerializer.DeserializeMsalV3(Byte[], Boolean)
ITokenCacheSerializer.SerializeAdalV3()
ITokenCacheSerializer.SerializeMsalV2()
ITokenCacheSerializer.SerializeMsalV3()

Extension Methods

SetCacheOptions(ITokenCache, CacheOptions)

Options for MSAL token caches.

MSAL maintains a token cache internally in memory. By default, this cache object is part of each instance of PublicClientApplication or ConfidentialClientApplication. This method allows customization of the in-memory token cache of MSAL.

MSAL's memory cache is different than token cache serialization. Cache serialization pulls the tokens from a cache (e.g. Redis, Cosmos, or a file on disk), where they are stored in JSON format, into MSAL's internal memory cache. Memory cache operations do not involve JSON operations.

External cache serialization remains the recommended way to handle desktop apps, web site and web APIs, as it provides persistence. These options do not currently control external cache serialization.

Detailed guidance for each application type and platform: https://aka.ms/msal-net-token-cache-serialization

Applies to