.NET CORE 3.1
I got an answer how to logout all clients from Identity Server.
I work by this example (chapter) REVOCATION.
But now I have a new problem. On OnSignedIn event I want to add the user id to the Redis Cache, but I dont know how.
This is a bad practice:
var sp = services.BuildServiceProvider();
var cache = sp.GetService<IDistributedCache>();
cache.SetString("helloFromRedis", "world");
var valueFromRedis = cache.GetString("helloFromRedis");
Console.WriteLine(valueFromRedis);
My Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddStackExchangeRedisCache(options =>
{
options.Configuration = RedisString;
});
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies", options =>
{
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
options.SlidingExpiration = true;
options.Events.OnSignedIn(a => {
// there I want to resolve cache and put userId from claims.
});
})
.AddOpenIdConnect("oidc", options =>
{
//...
});
}
How I can resolve Redis cache?