Table of Contents

Class DynamicProviderCache

Namespace
Fdyay.IdentityServer.Hosting
Assembly
Fdyay.IdentityServer.AspNetCore.dll

What the store last said about each scheme.

public sealed class DynamicProviderCache
Inheritance
DynamicProviderCache
Inherited Members

Remarks

It exists because the two halves of resolving a dynamic provider disagree about async. Looking one up is a store read; configuring the handler's options is IConfigureNamedOptions<TOptions>, which is synchronous and cannot read a store at all. So the scheme lookup — async, and always first — leaves what it found here for the options binding to pick up.

A singleton, and it has to be: AuthenticationMiddleware takes IAuthenticationSchemeProvider in its constructor and is built from the root provider when the pipeline is, so anything that provider depends on is captured for the life of the application. A scoped cache would fail scope validation at startup rather than serve a stale row.

Until 0.68.0 that was also recorded here as the reason a row edited in the store was not seen until a restart, which was wrong about its own mechanism: the entry is overwritten on every lookup, because DynamicAuthenticationSchemeProvider reads the store each time. Nothing here was ever stale. The framework's named-options cache was, and it is a singleton too, so it is reachable from one.

Which is why Remember(DynamicAuthenticationScheme) reports whether the row changed: that answer is what tells the scheme provider to drop the scheme's cached options so they are rebuilt from the new row. It is compared against a snapshot rather than the previously remembered object, because a store is free to hand back the same mutable instance it handed back last time — an in-memory one does — and comparing that object with itself would report no change however much it had been edited.

Methods

Find(string)

The row last remembered for scheme, or null when no lookup has resolved it.

public IdentityProvider? Find(string scheme)

Parameters

scheme string

The scheme name.

Returns

IdentityProvider

The stored provider, or null.

Remember(DynamicAuthenticationScheme)

Records what the store just said, and answers whether the options built from it are stale.

public bool Remember(DynamicAuthenticationScheme scheme)

Parameters

scheme DynamicAuthenticationScheme

Returns

bool

Remarks

False on the first sighting of a scheme, which is correct rather than convenient: nothing can have cached options for a scheme that has never been resolved, and a statically registered name never reaches here at all because the lookup answers it before asking the store.

Takes the DynamicAuthenticationScheme the lookup hands out, and reads the row through it, as Duende's DynamicAuthenticationSchemeCache keeps the scheme. Until 0.105.0 it took the row.