TokenCacheExtensions.AddDistributedTokenCache Methode

Definitie

Voeg een gedistribueerde tokencache toe.

public static Microsoft.Identity.Client.IConfidentialClientApplication AddDistributedTokenCache(this Microsoft.Identity.Client.IConfidentialClientApplication confidentialClientApp, Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> initializeDistributedCache);
static member AddDistributedTokenCache : Microsoft.Identity.Client.IConfidentialClientApplication * Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> -> Microsoft.Identity.Client.IConfidentialClientApplication
<Extension()>
Public Function AddDistributedTokenCache (confidentialClientApp As IConfidentialClientApplication, initializeDistributedCache As Action(Of IServiceCollection)) As IConfidentialClientApplication

Parameters

confidentialClientApp
IConfidentialClientApplication

Vertrouwelijke clienttoepassing.

initializeDistributedCache
Action<IServiceCollection>

Actie die een IServiceCollection en waarmee u uw gedistribueerde cache initialiseert.

Retouren

De toepassing voor ketening.

Voorbeelden

Met de volgende code wordt een tokencache toegevoegd op basis van REDIS en wordt de configuratie geïnitialiseerd.

app.AddDistributedTokenCache(services =>
{
     // Redis token cache
     // Requires to reference Microsoft.Extensions.Caching.StackExchangeRedis
     services.AddStackExchangeRedisCache(options =>
     {
         options.Configuration = "localhost";
         options.InstanceName = "Redis";
     });
});

U kunt ook met de volgende code een tokencache toevoegen op basis van PostgreSQL en de configuratie initialiseren.

app.AddDistributedTokenCache(services =>
{
     // PostgreSQL token cache
     // Requires to reference Microsoft.Extensions.Caching.Postgres
     services.AddDistributedPostgresCache(options =>
     {
         options.ConnectionString = "Host=localhost;Database=mydb;Username=myuser;Password=mypassword";
         options.SchemaName = "public";
         options.TableName = "token_cache";
         options.CreateIfNotExists = true;
     });
});

Opmerkingen

Gebruik deze methode niet in ASP.NET Core. Voeg in plaats daarvan de methode ConfigureServices toe.

Van toepassing op