Coder Social home page Coder Social logo

rsft.identity3.cacheredis's Introduction

Redis Cache For Identity Server 3

rolosoft_public_packages MyGet Build Status

About

A library that delivers a Redis based implementation of Identity Server 3 extension points for:

  • ICache<Client>
  • ICache<IEnumerable<Scope>>
  • ICache<IEnumerable<Claim>>

Who and what is this for?

Identity Server 3 default implementations for Client, Scope and Claim persistence are volatile in-memory stores. This is no problem for single server solutions. However, in load balanced environments, the default in-memory stores fail.

In such shared server scenarios, a central persistence store is required. Redis offers a perfect solution.

Features and Benefits

  • Thread safe, high performance implementation
  • Extensive async logging built in using SLAB
  • Built in compression (can be disabled if required)
  • Optional configuration over-rides for cache duration, cache prefix and compression options

Installation

From Nuget

install-package Rsft.Identity3.CacheRedis

Quick Start

See unit / integration tests for full examples. A default setup might look like this:

/*Create a singleton instance of our Redis integration extension */
var caches = RedisCacheFactory.Create(RedisConnectionString);

/*Assign caches to vars for ease of single-step debugging / inspection etc.*/
var clientCache = caches.ClientCache;
var scopesCache = caches.ScopesCache;
var userServiceCache = caches.UserServiceCache;

/*Create Identity Server 3 with default, in memory persistence stores. NOTE: persistence stores will be your SQL, EF or storage production stores or whatever*/
var identityServerServiceFactory = new IdentityServerServiceFactory().UseInMemoryClients(new List<Client>()).UseInMemoryScopes(new List<Scope>()).UseInMemoryUsers(new List<InMemoryUser>());

/*Add the Redis cache stores as extension objects into Identity Server 3*/
identityServerServiceFactory.ConfigureClientStoreCache(new Registration<ICache<Client>>(clientCache));
identityServerServiceFactory.ConfigureScopeStoreCache(new Registration<ICache<IEnumerable<Scope>>>(scopesCache));
identityServerServiceFactory.ConfigureUserServiceCache(new Registration<ICache<IEnumerable<Claim>>>(userServiceCache));

Advanced Topics

Connection Multiplexer

A Redis ConnectionMultiplexer or connection string is required to create a connection to Redis.

There are 3 ways of doing this:

  1. Pass in a connection string e.g.
var cache = RedisCacheFactory.Create("<your connection string>");
  1. Pass in an existing Connection Multiplexer e.g.
var cache = RedisCacheFactory.Create(MyConnectionMultiplexer);

Note: If you are creating a Connection Multiplexer yourself, be sure to ensure that it is a singleton instance as per recommendations described here

  1. Connection string In App.config or Web.config, ConnectionString or value named 'Rsft:Identity3:CacheConnectionString'

We use Azure CloudConfigurationManager wo ensure that configuration options are as diverse as possible for Azure hosting options (e.g Cloud service, Web etc)

e.g. Web.config or App.config

<appSettings>
    <add key="Rsft:Identity3:CacheConnectionString" value="MyConnectionString"/>
</appSettings>

e.g. *.cscfg

<ConfigurationSettings>
  <Setting name="Rsft:Identity3:CacheConnectionString" value="MyConnectionString" />
</ConfigurationSettings>

Configuration

Customize configuration by passing in an optional IConfiguration<RedisCacheConfigurationEntity> to the RedisCacheFactory.Create(..) method.

Configuration options are:

Option Name Description Default
CacheDuration Duration of cache (in seconds) 3600
RedisCacheDefaultPrefix Prefix of keys to store in cache rsftid3cache
UseObjectCompression Use compression to store objects in Redis ? true

Logging

Extensive async logging is built in using SLAB.

There are two logs:

  • Exception - Add listener(s) for ExceptionLoggingEventSource.Log
  • Activity - Add listener(s) for ActivityLoggingEventSource.Log

Example of Creating Console Listener for Exception Logging.

var observableEventListener = new ObservableEventListener();
observableEventListener.EnableEvents(ExceptionLoggingEventSource.Log, EventLevel.LogAlways);
observableEventListener.LogToConsole();

See unit tests in source code for more examples of logging verbosity options and filters.

rsft.identity3.cacheredis's People

Contributors

simon-paramore avatar roly67 avatar emh-rowland-oconnor avatar

Stargazers

Oucema Zitoun avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.