![]() |
VOOZH | about |
dotnet add package OpaDotNet.Extensions.AspNetCore --version 2.0.0-preview0029
NuGet\Install-Package OpaDotNet.Extensions.AspNetCore -Version 2.0.0-preview0029
<PackageReference Include="OpaDotNet.Extensions.AspNetCore" Version="2.0.0-preview0029" />
<PackageVersion Include="OpaDotNet.Extensions.AspNetCore" Version="2.0.0-preview0029" />Directory.Packages.props
<PackageReference Include="OpaDotNet.Extensions.AspNetCore" />Project file
paket add OpaDotNet.Extensions.AspNetCore --version 2.0.0-preview0029
#r "nuget: OpaDotNet.Extensions.AspNetCore, 2.0.0-preview0029"
#:package OpaDotNet.Extensions.AspNetCore@2.0.0-preview0029
#addin nuget:?package=OpaDotNet.Extensions.AspNetCore&version=2.0.0-preview0029&prereleaseInstall as a Cake Addin
#tool nuget:?package=OpaDotNet.Extensions.AspNetCore&version=2.0.0-preview0029&prereleaseInstall as a Cake Tool
This is AspNetCore specific extensions for OpaDotNet project.
dotnet add package OpaDotNet.Extensions.AspNetCore
Add policy file ./Policy/policy.rego
package example
import future.keywords.if
# METADATA
# entrypoint: true
allow if {
true
}
# METADATA
# entrypoint: true
deny if {
false
}
The code:
using System.Security.Claims;
using System.Text.Encodings.Web;
using System.Text.Json;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.Options;
using OpaDotNet.Extensions.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
// Register core services.
builder.Services.AddOpaAuthorization(
cfg =>
{
// Get policies from the file system.
cfg.AddFileSystemPolicySource();
// Configure.
cfg.AddConfiguration(
p =>
{
// Allow to pass all headers as policy query input.
p.AllowedHeaders.Add(".*");
// Path where look for rego policies.
p.PolicyBundlePath = "./Policy";
p.EngineOptions = new()
{
SerializationOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
},
};
}
);
}
);
// In real scenarios here will be more sophisticated authentication.
builder.Services.AddAuthentication()
.AddScheme<AuthenticationSchemeOptions, NopAuthenticationSchemeHandler>(
NopAuthenticationSchemeHandler.AuthenticationSchemeName,
null
);
builder.Services.AddAuthorization();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
// Will evaluate example/allow rule and return 200.
app.MapGet("/allow", [OpaPolicyAuthorize("example", "allow")] () => "Hi!");
// Will evaluate example/deny rule and return 403.
app.MapGet("/deny", [OpaPolicyAuthorize("example", "deny")] () => "Should not be here!");
app.Run();
internal class NopAuthenticationSchemeHandler : AuthenticationHandler<AuthenticationSchemeOptions>
{
public const string AuthenticationSchemeName = "Nop";
public NopAuthenticationSchemeHandler(
IOptionsMonitor<AuthenticationSchemeOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock) : base(options, logger, encoder, clock)
{
}
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
{
var principal = new ClaimsPrincipal();
var ticket = new AuthenticationTicket(principal, AuthenticationSchemeName);
var result = AuthenticateResult.Success(ticket);
return Task.FromResult(result);
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.1.2 | 501 | 6/8/2026 |
| 3.1.0 | 328 | 12/15/2025 |
| 3.0.3 | 433 | 3/11/2025 |
| 3.0.0-preview-0047 | 301 | 3/5/2025 |
| 3.0.0-preview-0032 | 187 | 2/26/2025 |
| 3.0.0-preview-0005 | 158 | 11/10/2024 |
| 3.0.0-preview-0001 | 197 | 10/25/2024 |
| 3.0.0-preview-0000 | 186 | 10/25/2024 |
| 2.4.1 | 478 | 2/12/2024 |
| 2.4.0 | 331 | 1/30/2024 |
| 2.3.0 | 279 | 1/15/2024 |
| 2.2.0 | 231 | 1/10/2024 |
| 2.1.0 | 348 | 11/21/2023 |
| 2.0.0 | 312 | 10/11/2023 |
| 2.0.0-preview0029 | 246 | 10/10/2023 |
| 2.0.0-preview0027 | 211 | 10/9/2023 |
| 2.0.0-preview0026 | 211 | 10/4/2023 |
| 2.0.0-preview0025 | 235 | 10/3/2023 |
| 2.0.0-preview0024 | 194 | 9/29/2023 |
| 2.0.0-preview0021 | 251 | 9/28/2023 |