Eliassen.AspNetCore.Mvc 0.1.83

This package has a SemVer 2.0.0 package version: 0.1.83+10.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Eliassen.AspNetCore.Mvc --version 0.1.83                
NuGet\Install-Package Eliassen.AspNetCore.Mvc -Version 0.1.83                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Eliassen.AspNetCore.Mvc" Version="0.1.83" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Eliassen.AspNetCore.Mvc --version 0.1.83                
#r "nuget: Eliassen.AspNetCore.Mvc, 0.1.83"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Eliassen.AspNetCore.Mvc as a Cake Addin
#addin nuget:?package=Eliassen.AspNetCore.Mvc&version=0.1.83

// Install Eliassen.AspNetCore.Mvc as a Cake Tool
#tool nuget:?package=Eliassen.AspNetCore.Mvc&version=0.1.83                

Eliassen.AspNetCore.Mvc

Summary

This code is part of an open-source project that provides extensions for ASP.NET Core. The extensions include authentication, authorization, and search query support. The code contains several functions and classes that are used to implement these extensions.

Configuration

The configuration options for this code can be found in the ServiceCollectionExtensions class. The main configuration options are:

  • TryAddAspNetCoreExtensions This function adds the necessary services to support all ASP.NET Core extensions provided by this library. It takes several parameters, including requireAuthenticatedByDefault, requireApplicationUserId, and authorizationPolicyBuilder.

  • AddRequireAuthenticatedUser This function adds authentication requirements to the service collection. It takes two parameters, requireApplicationUserId and authorizationPolicyBuilder.

  • TryAddCommonOpenApiExtensions This function enables extensions for Swagger/OpenAPI.

  • TryAddAspNetCoreSearchQuery This function enables extensions for shared search query extensions.

Example

Here is an example of how to configure the code

public void ConfigureServices(IServiceCollection services)
{
    services.TryAddAspNetCoreExtensions(
        requireAuthenticatedByDefault: true,
        requireApplicationUserId: true,
        authorizationPolicyBuilder: policyBuilder =>
        {
            policyBuilder.RequireClaim("scope", "api1");
            policyBuilder.RequireClaim("scope", "api2");
        }
    );

    services.AddRequireAuthenticatedUser(
        requireApplicationUserId: true,
        authorizationPolicyBuilder: policyBuilder =>
        {
            policyBuilder.RequireClaim("role", "admin");
        }
    );

    services.TryAddCommonOpenApiExtensions();
    services.TryAddAspNetCoreSearchQuery();
}

In this example, authentication is required by default, and the application user ID is also required. Additionally, two authorization policies are added: one that requires authentication and two specific claims (scope), and another that requires authentication and a specific claim (role). Finally, the Swagger/OpenAPI and search query extensions are enabled.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Eliassen.AspNetCore.Mvc:

Package Downloads
Eliassen.AspNetCore.JwtAuthentication

Package Description

Eliassen.Common.AspNetCore

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.85 45 10/10/2024
0.1.84 42 10/10/2024
0.1.83 44 9/27/2024
0.1.82 169 8/23/2024
0.1.81 101 8/1/2024
0.1.81-dev-gh-pipline.3 45 8/1/2024