Udostępnij za pośrednictwem


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.

Properties

HasStateChanged
Obsolete.

Gets or sets the flag indicating whether the state of the cache has changed. MSAL methods set this flag after any change. Caller applications should reset the flag after serializing and persisting the state of the cache.

Methods

Deserialize(Byte[])
Obsolete.

Deserializes the token cache from a serialization blob in the unified cache format Obsolete: Please use specialized Deserialization methods. DeserializeMsalV2(Byte[]) replaces Deserialize(Byte[])SerializeMsalV3()/DeserializeMsalV3(Byte[], Boolean) Is our recommended way of serializing/deserializing. DeserializeAdalV3(Byte[]) For interoperability with ADAL.NET v3

DeserializeAdalV3(Byte[])
Obsolete.

This is removed in MSAL.NET v4. Read more: https://aka.ms/msal-net-4x-cache-breaking-change

DeserializeMsalV2(Byte[])
Obsolete.

This is removed in MSAL.NET v4. Read more: https://aka.ms/msal-net-4x-cache-breaking-change

DeserializeMsalV3(Byte[], Boolean)
Obsolete.

This is removed in MSAL.NET v4. Read more: https://aka.ms/msal-net-4x-cache-breaking-change

DeserializeUnifiedAndAdalCache(CacheData)
Obsolete.

Deserializes the token cache from a serialization blob in both format (ADAL V3 format, and unified cache format)

Serialize()
Obsolete.

Serializes using the SerializeMsalV2() serializer. Obsolete: Please use specialized Serialization methods. SerializeMsalV2() replaces Serialize(). SerializeMsalV3()/DeserializeMsalV3(Byte[], Boolean) Is our recommended way of serializing/deserializing. SerializeAdalV3() For interoperability with ADAL.NET v3.

SerializeAdalV3()
Obsolete.

This is removed in MSAL.NET v4. Read more: https://aka.ms/msal-net-4x-cache-breaking-change

SerializeMsalV2()
Obsolete.

This is removed in MSAL.NET v4. Read more: https://aka.ms/msal-net-4x-cache-breaking-change

SerializeMsalV3()
Obsolete.

This is removed in MSAL.NET v4. Read more: https://aka.ms/msal-net-4x-cache-breaking-change

SerializeUnifiedAndAdalCache()
Obsolete.

Serializes the entire token cache in both the ADAL V3 and unified cache formats.

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