Black.Beard.Policies 1.0.11

There is a newer version of this package available.
See the version list below for details.
dotnet add package Black.Beard.Policies --version 1.0.11
                    
NuGet\Install-Package Black.Beard.Policies -Version 1.0.11
                    
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="Black.Beard.Policies" Version="1.0.11" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Black.Beard.Policies" Version="1.0.11" />
                    
Directory.Packages.props
<PackageReference Include="Black.Beard.Policies" />
                    
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 Black.Beard.Policies --version 1.0.11
                    
#r "nuget: Black.Beard.Policies, 1.0.11"
                    
#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 Black.Beard.Policies@1.0.11
                    
#: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=Black.Beard.Policies&version=1.0.11
                    
Install as a Cake Addin
#tool nuget:?package=Black.Beard.Policies&version=1.0.11
                    
Install as a Cake Tool

Policy

Manage the policy rules

Build status

any samples for Create policy

Create an alias for using in the policy like claim name

alias role : ""http://schemas.microsoft.com/ws/2008/06/identity/claims/role""

Create a policy like a claim ope is required but the value is not important

policy p1 : ope+

Create a policy like a role admin is required

policy p1 : role=admin

Create a policy like a role can't be guest

policy p1 : role != guest

Create a policy like a role admin is required

policy p1 : (role = admin)

Create a policy like a role can't be guest

policy p1 : !(role == guest)

Create a policy like a role can be admin or guest

policy p1 : role in [admin, guest]

Create a policy like a role can't be admin or guest

policy p1 : role !in [admin, guest]

Create a policy like a role must not to have admin and guest

policy p1 : role !has [admin, guest]

Create a policy like a role must to have admin and guest

policy p1 : role has [admin, guest]

Create a policy like the value to evaluate is in another object with a property name equal to "property" and value equal to 1

policy p1 : source2.property = 1

Create a policy like the value to evaluate is in another object with a property name equal to "property" and value equal to 1

policy p1 : source2.property = 1

Create a policy like that check if greater than 18

policy isAdult : Identity.Age >= 18

Add category on a rule

policy p1 (web) : Identity.IsAuthenticated

How to use library


string policyPayload = @"// your rules";

var policies = Policy.Evaluate(policyPayload);
if (!policies.Diagnostics.Success)
    throw new Exception("Failed to evaluate file policies");
var evaluator = new PolicyEvaluator(policies);
if (evaluator.Evaluate(policyRule.Name, c.User, out RuntimeContext context))
{
    // access granted
}

If you have a web site, reference nuget package Black.Beard.Policy.Web

WebApplicationBuilder builder;
builder.AddPolicy("file path", c => true );

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

sample of policy file


/* base rules */
policy isAuthenticated
    : Identity.IsAuthenticated

policy isAnonymous  
    : !Identity.IsAuthenticated

policy IsAdmin
    : role = administrator

policy IsUser
    : role = user


/* default rules */
policy default
    : isAuthenticated

policy fallback
    : isAnonymous


/* web rules */
policy Mycontroler.get (web_root)
    : isAuthenticated

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 (1)

Showing the top 1 NuGet packages that depend on Black.Beard.Policies:

Package Downloads
Black.Beard.Policy.Web

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.20 233 5/15/2025
1.0.19 230 5/15/2025
1.0.18 245 5/15/2025
1.0.12 174 3/22/2025
1.0.11 127 3/21/2025
1.0.10 157 3/20/2025
1.0.9 152 3/20/2025
1.0.7 156 3/17/2025
1.0.5 148 3/17/2025
1.0.4 143 3/17/2025
1.0.3 150 3/17/2025
1.0.2 149 3/17/2025