OpenPolicyAgent.Opa.AspNetCore 0.2.1

dotnet add package OpenPolicyAgent.Opa.AspNetCore --version 0.2.1
                    
NuGet\Install-Package OpenPolicyAgent.Opa.AspNetCore -Version 0.2.1
                    
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="OpenPolicyAgent.Opa.AspNetCore" Version="0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenPolicyAgent.Opa.AspNetCore" Version="0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="OpenPolicyAgent.Opa.AspNetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenPolicyAgent.Opa.AspNetCore --version 0.2.1
                    
#r "nuget: OpenPolicyAgent.Opa.AspNetCore, 0.2.1"
                    
#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.
#:package OpenPolicyAgent.Opa.AspNetCore@0.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenPolicyAgent.Opa.AspNetCore&version=0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=OpenPolicyAgent.Opa.AspNetCore&version=0.2.1
                    
Install as a Cake Tool

OPA ASP.NET Core SDK

The documentation for this SDK lives under docs/, with reference documentation available at https://open-policy-agent.io/opa-aspnetcore/

You can use the OPA C# ASP.NET Core SDK to connect Open Policy Agent and EOPA deployments to your ASP.NET Core applications using the included Middleware implementation.

Would you prefer a plain C# API instead of ASP.NET Core? Check out the OPA C# SDK.

SDK Installation

This package is published on NuGet as OpenPolicyAgent.Opa.AspNetCore. The NuGet page includes up-to-date instructions on how to add it as a dependency to your C# project.

If you're using the dotnet CLI, this should look like:

dotnet add package OpenPolicyAgent.Opa.AspNetCore

SDK Example Usage (high-level)

using OpenPolicyAgent.Opa;
using OpenPolicyAgent.Opa.AspNetCore;

// ...

string opaUrl = System.Environment.GetEnvironmentVariable("OPA_URL") ?? "http://localhost:8181";
OpaClient opa = new OpaClient(opaUrl);

var builder = new WebHostBuilder()
    .ConfigureServices(services =>
    {
        services.AddAuthentication( /* ... your authentication setup here ... */ );
        services.AddRouting();
        // ...
    }).Configure(app =>
    {
        app.UseRouting();
        app.UseAuthentication();
        app.UseMiddleware<OpaAuthorizationMiddleware>(opa, "authz/exampleapp/routes/allow");
        // ...
        // Your controller/routes added here.
    });

var app = builder.Build();
app.Run();

Policy Input/Output Schema

Documentation for the required input and output schema of policies used by the OPA ASP.NET Core SDK can be found here

Build Instructions

To build the SDK, use dotnet build. The resulting library files will be in src/OpenPolicyAgent.Opa.AspNetCore/bin/Debug/net8.0.

To build the documentation site, run docfx docs/docfx.json -o OUTPUT_DIR. You should replace OUTPUT_DIR with a directory on your local system where you would like the generated docs to be placed (the default behavior without -o will place the generated HTML docs site under the docs/_site folder in this repo). You can also preview the documentation site using docfx docs/docfx.json --serve, which will serve the docs on http://localhost:8080 until you use Ctrl+C to exit.

To run the unit tests, you can use dotnet test.

Community

For questions, discussions, and announcements, please join the OPA community on Slack!

Development

For development docs, see DEVELOPMENT.md.

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.1 265 10/3/2025
0.2.0 112 10/3/2025
0.1.7 917 8/29/2025