{"id":17336220,"url":"https://github.com/alsami/identityserver4.contrib.caching","last_synced_at":"2025-06-13T10:09:43.197Z","repository":{"id":78582880,"uuid":"187603398","full_name":"alsami/IdentityServer4.Contrib.Caching","owner":"alsami","description":null,"archived":false,"fork":false,"pushed_at":"2019-12-26T10:03:29.000Z","size":1239,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-13T10:09:19.781Z","etag":null,"topics":["caching","caching-library","identityserver4","oauth2","openid","redis"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alsami.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-05-20T08:50:33.000Z","updated_at":"2022-12-16T02:56:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"fb5058c3-a03e-4c73-84f0-de4838a8cf75","html_url":"https://github.com/alsami/IdentityServer4.Contrib.Caching","commit_stats":null,"previous_names":["cleancodelabs/identityserver4.contrib.caching.distributed"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/alsami/IdentityServer4.Contrib.Caching","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FIdentityServer4.Contrib.Caching","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FIdentityServer4.Contrib.Caching/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FIdentityServer4.Contrib.Caching/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FIdentityServer4.Contrib.Caching/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alsami","download_url":"https://codeload.github.com/alsami/IdentityServer4.Contrib.Caching/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FIdentityServer4.Contrib.Caching/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259624736,"owners_count":22886330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["caching","caching-library","identityserver4","oauth2","openid","redis"],"created_at":"2024-10-15T15:28:43.714Z","updated_at":"2025-06-13T10:09:43.166Z","avatar_url":"https://github.com/alsami.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IdentityServer4.Contrib.Caching\r\n\r\n## IdentityServer4.Contrib.Caching.Redis\r\n\r\n[![NuGet](https://img.shields.io/nuget/dt/IdentityServer4.Contrib.Caching.Redis.svg)](https://www.nuget.org/packages/IdentityServer4.Contrib.Caching.Redis)\r\n[![NuGet](https://img.shields.io/nuget/vpre/IdentityServer4.Contrib.Caching.Redis.svg)](https://www.nuget.org/packages/IdentityServer4.Contrib.Caching.Redis)\r\n[![NuGet](https://img.shields.io/nuget/v/IdentityServer4.Contrib.Caching.Redis.svg)](https://www.nuget.org/packages/IdentityServer4.Contrib.Caching.Redis)\r\n[![Build Status](https://travis-ci.com/cleancodelabs/IdentityServer4.Contrib.Caching.svg?branch=master)](https://travis-ci.com/cleancodelabs/IdentityServer4.Contrib.Caching)\r\n\r\nThis library written in c# and targeting  `netcoreapp3.0`, provides an implementation of `IPersistedGrantStore` for `IdentityServer4` using the `IDistributedCache` interface and Redis implementation located in [Microsoft.Extensions.Caching.StackExchangeRedis](https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis/2.2.5), that can easily be registered using provided extension methods for `IIdentityServerBuilder`.\r\n\r\nIt also makes use of [RedLock](https://www.nuget.org/packages/RedLock/) for pessimistic locking of resources in Redis.\r\n\r\n## How it works\r\n\r\n`IdentityServer4` provides an interface called `IPersistedGrantStore` located in the package [IdentityServer4.Stores](https://github.com/IdentityServer/IdentityServer4/blob/314bb5a9f05a296d4ab375e02451ff0a9e9c7bac/src/Storage/src/Stores/IPersistedGrantStore.cs#L14).\r\nAny store can be registered using a simple extensions method provided by `IdentityServer4`. This package makes use of it and implements a store that is distributed and can therefor be easily used in a load-balanced environment.\r\n\r\nThere are four keyed combinations stored:\r\n\r\n* Key of `PersistedGrant`\r\n* Subject-Id of `PersistedGrant`\r\n* Combination of Subject- and Client-Id of `PersistedGrant`\r\n* Combination of Subject-, Client-Id and Type of `PersistedGrant`\r\n\r\nWhile a key is unique and therefor only stored as a single object, all other combinations are not. For instance a given subject-id can be a user-id and a user might log into services using multiple front-ends. Those instances are appended and that's where `RedLock` kicks in.\r\nTo ensure that no values are overwritten, `RedLock` is used to temporally lock the resource that is then loaded, appended, released and stored.   \r\n\r\n![elements](assets/sample_stored_elements.png)\r\n\r\n## Installation\r\n\r\nThis package is available via nuget. You can install it using Visual-Studio-Nuget-Browser or by using the dotnet-cli.\r\n\r\n`dotnet add package IdentityServer4.Contrib.Caching.Redis`\r\n\r\nIf you want to add a specific version of this package\r\n\r\n`dotnet add package IdentityServer4.Contrib.Caching.Redis --version 1.0.0`\r\n\r\nFor more information please visit the official dotnet-cli documentation.\r\n\r\n## Usage\r\n\r\nOnly thing you need to do is call an extension method on the `IIdentityServerBuilder` that you are already using.\r\n\r\n```csharp\r\npublic void ConfigureServices(IServiceCollection services)\r\n{\r\n    services.AddIdentityServer()\r\n        // more code here\r\n        .AddDistributedRedisCache(configuration: \"127.0.0.1:6379\", instanceName: \"my-redis-instance-name\"); // \u003c- this!\r\n        \r\n    // more code here \r\n}\r\n```\r\n\r\nOptionally you can pass in a caching prefix. The default is \"_IdentityServer_Distributed_Caching_\".\r\n\r\n```csharp\r\npublic void ConfigureServices(IServiceCollection services)\r\n{\r\n    services.AddIdentityServer()\r\n        // more code here\r\n        .AddDistributedRedisCache(configuration: \"127.0.0.1:6379\", instanceName: \"my-redis-instance-name\", \r\n            cachingPrefix: \"_my-identityserver-caching-prefix_); // \u003c- this!\r\n        \r\n    // more code here \r\n}\r\n```\r\n\r\nYou can also pass in your on configuration-builder for `RedisCacheOptions` and `RedisCacheGrantStoreConfiguration`\r\n\r\n```csharp\r\npublic void ConfigureServices(IServiceCollection services)\r\n{\r\n    services.AddIdentityServer()\r\n        // more code here\r\n        .AddDistributedRedisCache(options =\u003e  // \u003c- this!\r\n            {\r\n            options.Configuration: \"127.0.0.1:6379\";\r\n            options.InstanceName: \"my-redis-instance-name\";\r\n            }, \r\n            options =\u003e options.CachingPrefix = \"_my-identityserver-caching-prefix_\");\r\n        \r\n    // more code here \r\n}\r\n```\r\n\r\nThird option also allows you to configure the `RedLockOptions` to configure the retry-count and retry-timeout.\r\n\r\n```csharp\r\npublic void ConfigureServices(IServiceCollection services)\r\n{\r\n    services.AddIdentityServer()\r\n        // more code here\r\n        .AddDistributedRedisCache(options =\u003e  // \u003c- this!\r\n            {\r\n            options.Configuration: \"127.0.0.1:6379\";\r\n            options.InstanceName: \"my-redis-instance-name\";\r\n            }, \r\n            options =\u003e options.CachingPrefix = \"_my-identityserver-caching-prefix_\",\r\n            options =\u003e \r\n            {\r\n                options.LockRetryCount = 1,\r\n                options.LockRetryDelay = TimeSpan.FromSeconds(1)\r\n            });\r\n        \r\n    // more code here \r\n}\r\n```\r\n\r\nThat's it! You are good to go and everything required to use `IDistributedCache` for Redis and IdentityServer has been setup.\r\n\r\nFor more details and information, have a look at the [tests](test/IdentityServer4.Contrib.Caching.Redis.Tests).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falsami%2Fidentityserver4.contrib.caching","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falsami%2Fidentityserver4.contrib.caching","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falsami%2Fidentityserver4.contrib.caching/lists"}