Skip to content

Latest commit

 

History

History
72 lines (49 loc) · 3.06 KB

README.md

File metadata and controls

72 lines (49 loc) · 3.06 KB

Identity.Redis

ASP.NET Identity Redis Provider

Build status Quality Gate Status

Nuget packages

Aguacongas.Identity.Redis

Setup

You setup Redis stores using one AddRedisStores extension method

You can setup Redis stores with a redis configuration string:

services.AddIdentity<ApplicationUser, IdentityRole>()
    .AddRedisStores("localhost")
    .AddDefaultTokenProviders();

Or with an Action receiving an instance of a StackExchange.Redis.ConfigurationOptions:

services.AddIdentity<ApplicationUser, IdentityRole>()
    .AddRedisStores(options =>
    {
        options.EndPoints.Add("localhost:6379");
    })
    .AddDefaultTokenProviders();

Both methods can take a int? database parameter to specify the Redis database to use:

services.AddIdentity<ApplicationUser, IdentityRole>()
    .AddRedisStores(Configuration.GetValue<string>("ConnectionStrings:DefaultConnection"), 1)
    .AddDefaultTokenProviders();

Or, you can use AddRedisStores with a Func<IdentityProvider, StackExchange.Redis.IDatabase>:

var multiplexer = ConnectionMultiplexer.Connect("localhost");

services.AddIdentity<ApplicationUser, IdentityRole>()
    .AddRedisStores(provider => multiplexer.GetDatabase())
    .AddDefaultTokenProviders();

Logging

A logger is automaticaly injected to the underlying StackExchange.Redis.ConnectionMultiplexer by AddRedisStores methods.
This logger write traces, (LogLevel = LogLevel.Trace), to enable it add a filter to your logging configuration:

services.AddLogging(builder =>
{
    builder.AddDebug()
        .AddConsole()
        .AddFilter("Aguacongas.Identity.Redis", LogLevel.Trace);
})

Obviously, if you use AddRedisStores with a Func<IdentityProvider, StackExchange.Redis.IDatabase> the logger is not injected automaticaly.

Sample

The sample is a copy of IdentitySample.Mvc sample using a Redis database.

Tests

This library is tested using Microsoft.AspNetCore.Identity.Specification.Tests, the shared test suite for Asp.Net Identity Core store implementations.