Table of Contents

Class LocalApiAuthenticationExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
Fdyay.IdentityServer.AspNetCore.dll

Registers authentication for an API this server hosts itself.

public static class LocalApiAuthenticationExtensions
Inheritance
LocalApiAuthenticationExtensions
Inherited Members

Remarks

Both methods are safe to call more than once. That is not politeness: a library that adds the local API and a host that also adds it is an ordinary shape, and the collision AuthenticationOptions.AddScheme throws on surfaces from inside UseIdentityServer as "Scheme already exists", naming neither caller. This repository has paid for that once already — 0.33.1, where calling AddIdentityServer() twice refused to boot on a duplicate validator.

Methods

AddLocalApi(AuthenticationBuilder, Action<LocalApiAuthenticationOptions>?)

Adds the local API scheme, so an endpoint can require a token this server issued.

public static AuthenticationBuilder AddLocalApi(this AuthenticationBuilder builder, Action<LocalApiAuthenticationOptions>? configureOptions = null)

Parameters

builder AuthenticationBuilder
configureOptions Action<LocalApiAuthenticationOptions>

Returns

AuthenticationBuilder

Remarks

The scheme only. A host that also wants the matching authorization policy — the ordinary case, since an endpoint is protected by a policy rather than by a scheme — calls AddLocalApiAuthentication(IServiceCollection, Action<LocalApiAuthenticationOptions>?) instead.

A second call configures the scheme already registered rather than adding it again, so options from both callers compose the way Configure always does and neither silently wins.

AddLocalApi(AuthenticationBuilder, string, Action<LocalApiAuthenticationOptions>?)

Adds the local API handler under a scheme name of the host's. Duende's.

public static AuthenticationBuilder AddLocalApi(this AuthenticationBuilder builder, string authenticationScheme, Action<LocalApiAuthenticationOptions>? configureOptions)

Parameters

builder AuthenticationBuilder
authenticationScheme string
configureOptions Action<LocalApiAuthenticationOptions>

Returns

AuthenticationBuilder

Remarks

For a host serving more than one local API, each wanting its own ExpectedScope or token mode: one scheme per API, each configured on its own. A second call with a name already added configures that scheme rather than adding it again, as the unnamed overload does.

AddLocalApi(AuthenticationBuilder, string, string?, Action<LocalApiAuthenticationOptions>?)

The same, with the name the scheme is shown under. Duende's.

public static AuthenticationBuilder AddLocalApi(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action<LocalApiAuthenticationOptions>? configureOptions)

Parameters

builder AuthenticationBuilder
authenticationScheme string
displayName string
configureOptions Action<LocalApiAuthenticationOptions>

Returns

AuthenticationBuilder

AddLocalApiAuthentication(IServiceCollection, Action<LocalApiAuthenticationOptions>?)

Adds the local API scheme and the policy an endpoint requires.

public static IServiceCollection AddLocalApiAuthentication(this IServiceCollection services, Action<LocalApiAuthenticationOptions>? configureOptions = null)

Parameters

services IServiceCollection
configureOptions Action<LocalApiAuthenticationOptions>

Returns

IServiceCollection

Remarks

Both together, because either alone is a half a host has to notice is missing: a scheme with no policy protects nothing until somebody writes one, and the policy names a scheme that has to exist. The policy pins the scheme explicitly rather than relying on the default, so an endpoint requiring it is answered by this handler even in a host whose default scheme is a browser cookie — which is every host that also serves the identity server's own pages.