Skip to content

ServiceCollectionExtensions Class

Extension methods for adding OpenID Connect (OIDC) server services to the Microsoft.Extensions.DependencyInjection.IServiceCollection. These methods simplify the integration of OIDC server capabilities into an ASP.NET Core application, allowing for the configuration of OIDC options and services necessary for authentication and authorization.

C#
public static class ServiceCollectionExtensions

Inheritance System.Object → ServiceCollectionExtensions

Methods

ServiceCollectionExtensions.AddOidcControllers(this IServiceCollection) Method

Adds OIDC controllers to the MVC application. This method is used internally to ensure that the OIDC server's controllers are available to handle authentication and authorization requests.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddOidcControllers(this Microsoft.Extensions.DependencyInjection.IServiceCollection services);

Parameters

services Microsoft.Extensions.DependencyInjection.IServiceCollection

The Microsoft.Extensions.DependencyInjection.IServiceCollection to add services to.

Returns

Microsoft.Extensions.DependencyInjection.IServiceCollection
The Microsoft.Extensions.DependencyInjection.IServiceCollection so additional calls can be chained.

ServiceCollectionExtensions.AddOidcMvc(this IServiceCollection) Method

Adds OIDC MVC services to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection. This method sets up MVC services required for handling OIDC endpoints and requests within an ASP.NET Core application.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddOidcMvc(this Microsoft.Extensions.DependencyInjection.IServiceCollection services);

Parameters

services Microsoft.Extensions.DependencyInjection.IServiceCollection

The Microsoft.Extensions.DependencyInjection.IServiceCollection to add services to.

Returns

Microsoft.Extensions.DependencyInjection.IServiceCollection
The Microsoft.Extensions.DependencyInjection.IServiceCollection so additional calls can be chained.

ServiceCollectionExtensions.AddOidcServices(this IServiceCollection, Action<OidcOptions,IServiceProvider>) Method

Adds OIDC server services to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection with provided configuration options and service provider.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddOidcServices(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Abblix.Oidc.Server.Common.Configuration.OidcOptions,System.IServiceProvider> configureOptions);

Parameters

services Microsoft.Extensions.DependencyInjection.IServiceCollection

The Microsoft.Extensions.DependencyInjection.IServiceCollection to add services to.

configureOptions System.Action<OidcOptions,System.IServiceProvider>

A delegate to configure the OidcOptions with the service provider.

Returns

Microsoft.Extensions.DependencyInjection.IServiceCollection
The Microsoft.Extensions.DependencyInjection.IServiceCollection so additional calls can be chained.

Remarks

The request pipeline must call app.UseCors() after app.UseRouting(); see the remarks on AddOidcServices(this IServiceCollection, Action<OidcOptions>) for why the protocol endpoints refuse to answer without it.

ServiceCollectionExtensions.AddOidcServices(this IServiceCollection, Action<OidcOptions>) Method

Adds OIDC server services to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection with provided configuration options. This method allows for configuring OIDC options to tailor the authentication server to your specific needs.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddOidcServices(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Abblix.Oidc.Server.Common.Configuration.OidcOptions> configureOptions);

Parameters

services Microsoft.Extensions.DependencyInjection.IServiceCollection

The Microsoft.Extensions.DependencyInjection.IServiceCollection to add services to.

configureOptions System.Action<OidcOptions>

A delegate to configure the OidcOptions.

Returns

Microsoft.Extensions.DependencyInjection.IServiceCollection
The Microsoft.Extensions.DependencyInjection.IServiceCollection so additional calls can be chained.

Remarks

The request pipeline must call app.UseCors() after app.UseRouting(). The protocol controllers carry CORS metadata, because browser-based clients read the discovery document, the key set and the token endpoint cross-origin - and ASP.NET Core routing refuses to serve any endpoint whose CORS metadata no middleware honours, so without that call every protocol endpoint answers 500. The policy itself is registered here; only the middleware call belongs to the host, since the framework accepts the middleware only when it runs after routing has selected an endpoint - a place no library can insert it from.

ServiceCollectionExtensions.AppPolicy(this CorsOptions, string, CorsSettings) Method

Configures the application's CORS policy according to the specified CorsSettings. This method enables the customization of CORS policies for OIDC endpoints, allowing for the specification of allowed origins, methods, and headers, as well as whether credentials are supported.

C#
public static void AppPolicy(this Microsoft.AspNetCore.Cors.Infrastructure.CorsOptions options, string policyName, Abblix.Oidc.Server.Mvc.Configuration.CorsSettings settings);

Parameters

options Microsoft.AspNetCore.Cors.Infrastructure.CorsOptions

The Microsoft.AspNetCore.Cors.Infrastructure.CorsOptions to configure.

policyName System.String

The name of the CORS policy, used to identify it.

settings CorsSettings

The CorsSettings that define the CORS policy.