Black.Beard.Policies
1.0.11
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
<PackageReference Include="Black.Beard.Policies" Version="1.0.11" />
<PackageVersion Include="Black.Beard.Policies" Version="1.0.11" />
<PackageReference Include="Black.Beard.Policies" />
paket add Black.Beard.Policies --version 1.0.11
#r "nuget: Black.Beard.Policies, 1.0.11"
#:package Black.Beard.Policies@1.0.11
#addin nuget:?package=Black.Beard.Policies&version=1.0.11
#tool nuget:?package=Black.Beard.Policies&version=1.0.11
Policy
Manage the policy rules
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 | Versions 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. |
-
net8.0
- Antlr4.Runtime.Standard (>= 4.13.1)
- Black.Beard.Adfs (>= 1.0.11)
- Black.Beard.Analysis (>= 1.0.133)
- Black.Beard.ComponentModel (>= 1.0.172)
- System.CodeDom (>= 9.0.1)
- System.IdentityModel.Tokens.Jwt (>= 8.6.1)
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.