TokenCacheExtensions.AddDistributedTokenCache Método

Definição

Adicione um cache de token distribuído.

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

Parâmetros

confidentialClientApp
IConfidentialClientApplication

Aplicativo cliente confidencial.

initializeDistributedCache
Action<IServiceCollection>

Ação executando um IServiceCollection e pelo qual você inicializa seu cache distribuído.

Retornos

O aplicativo para encadeamento.

Exemplos

O código a seguir adiciona um cache de token com base no REDIS e inicializa sua configuração.

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

Como alternativa, o código a seguir adiciona um cache de token com base no PostgreSQL e inicializa sua configuração.

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;
     });
});

Comentários

Não use esse método no ASP.NET Core. Em vez disso, basta adicionar o método ConfigureServices.

Aplica-se a