IdentityServer / IdentityServer4.AccessTokenValidation

IdentityServer Access Token Validation for ASP.NET Core
Apache License 2.0
544 stars 214 forks source link

Cache fallback #111

Closed Vandersteen closed 5 years ago

Vandersteen commented 5 years ago

In our current setup, we use EnableCache=true with Redis Distributed Cache. However, should the Redis server 'die' for a moment, the authorization blows up as it can't get it out of cache.

Is there a way to configure this so it uses cache if it is available, but does not blow up if it can't make a connection ?

As it is 'only' cache, it could be ignored if it is not found. Instead of throwing errors.

leastprivilege commented 5 years ago

What do you mean with "blow up" - if the cache cannot return the entry, then treat it as "no entry found".

Vandersteen commented 5 years ago

Well, currently with the redis cache implementation, it throws an exception if the connection is lost. Which 'crashes' the authentication flow, so the application stops working.

I worked around it by creating a wrapper around the RedisDistributedCache implementation

leastprivilege commented 5 years ago

So you are saying that there should be a try/catch around accessing the cache? And if it throws for whatever reason, it should be treated as "no cache item found"?

If yes - could you create a PR?

brockallen commented 5 years ago

Any update on this?

Vandersteen commented 5 years ago

So you are saying that there should be a try/catch around accessing the cache? And if it throws for whatever reason, it should be treated as "no cache item found"?

If yes - could you create a PR?

I've ended up with writing a wrapper around the IDistributedCache that get's registered - if for whatever reason it throws an exception, it just returns as if no cache was found.

With the wrapper - you don't have to do anything in this package - it might be something that this package could implement as well - but that is not my call.