Sparkdo.Authorization 1.0.1

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

Sparkdo.Authorization

Sparkdo 授权库,提供基于策略和权限的授权功能实现。

功能特性

  • 基于策略的授权:支持 ASP.NET Core 授权策略
  • 权限系统:灵活的权限定义和检查机制
  • 方法级授权:通过拦截器实现方法级别的授权控制
  • 多租户支持:支持多租户场景下的授权控制
  • 权限提供者:支持用户、角色、客户端等多种权限提供者
  • 本地化支持:支持授权错误消息的本地化
  • 与 Sparkdo 框架无缝集成

安装

<PackageReference Include="Sparkdo.Authorization" Version="x.x.x" />

核心组件

授权拦截器

  • AuthorizationInterceptor: 授权拦截器,用于拦截方法调用并执行授权检查
  • AuthorizationInterceptorRegistrar: 授权拦截器注册器

授权服务

  • ISparkdoAuthorizationService: Sparkdo 授权服务接口
  • DefaultSparkdoAuthorizationService: 默认 Sparkdo 授权服务实现
  • IMethodInvocationAuthorizationService: 方法调用授权服务接口
  • DefaultMethodInvocationAuthorizationService: 默认方法调用授权服务实现

权限管理

  • IPermissionChecker: 权限检查器接口
  • DefaultPermissionChecker: 默认权限检查器实现
  • IPermissionDefinitionManager: 权限定义管理器接口
  • DefaultPermissionDefinitionManager: 默认权限定义管理器实现
  • IPermissionValueProviderManager: 权限值提供者管理器接口
  • DefaultPermissionValueProviderManager: 默认权限值提供者管理器实现

权限提供者

  • UserPermissionValueProvider: 用户权限值提供者
  • RolePermissionValueProvider: 角色权限值提供者
  • ClientPermissionValueProvider: 客户端权限值提供者

权限定义存储

  • IStaticPermissionDefinitionStore: 静态权限定义存储接口
  • DefaultStaticPermissionDefinitionStore: 默认静态权限定义存储实现
  • IDynamicPermissionDefinitionStore: 动态权限定义存储接口
  • NullDynamicPermissionDefinitionStore: 空动态权限定义存储实现

策略提供者

  • ISparkdoAuthorizationPolicyProvider: Sparkdo 授权策略提供者接口
  • DefaultSparkdoAuthorizationPolicyProvider: 默认 Sparkdo 授权策略提供者实现

状态检查器

  • RequirePermissionsSimpleStateChecker: 需要权限的简单状态检查器
  • RequirePermissionsSimpleBatchStateChecker: 需要权限的批量简单状态检查器
  • RequireAuthenticatedSimpleStateChecker: 需要认证的简单状态检查器

使用示例

基本授权使用

[Authorize("MyPermission")]
public class MyService
{
    public void MyMethod()
    {
        // 此方法需要 "MyPermission" 权限才能访问
    }
}

[Authorize("MyPermission1,MyPermission2")]
public class AnotherService
{
    public void MyMethod()
    {
        // 此方法需要 "MyPermission1" 和 "MyPermission2" 权限才能访问
    }
}

权限检查

public class MyService
{
    private readonly IPermissionChecker _permissionChecker;
    
    public MyService(IPermissionChecker permissionChecker)
    {
        _permissionChecker = permissionChecker;
    }
    
    public async Task MyMethod()
    {
        if (await _permissionChecker.IsGrantedAsync("MyPermission"))
        {
            // 用户具有 "MyPermission" 权限
        }
    }
}

自定义权限定义

public class MyPermissionDefinitionProvider : PermissionDefinitionProvider
{
    public override void Define(IPermissionDefinitionContext context)
    {
        var myGroup = context.AddGroup("MyGroup", "我的权限组");
        
        myGroup.AddPermission("MyPermission", "我的权限");
    }
}

扩展性

该库提供了完整的授权功能实现,可以通过以下方式扩展:

  1. 实现自定义的权限提供者
  2. 实现自定义的权限定义存储
  3. 实现自定义的授权策略提供者
  4. 实现自定义的状态检查器
  5. 通过继承和重写默认实现来定制授权行为

所有公共接口和类都添加了详细的 XML 文档注释,便于开发者理解和使用。

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Sparkdo.Authorization:

Package Downloads
Sparkdo.Ddd.Application

Sparkdo DDD应用层库,提供DDD应用服务的基础实现

Sparkdo.UI.Navigation

library for the Sparkdo framework

Sparkdo.PermissionManagement.Domain

Sparkdo 权限管理领域库,提供权限管理功能的核心领域模型、仓储接口和业务逻辑实现

Sparkdo.AspNetCore

Sparkdo ASP.NET Core 集成库,提供与 ASP.NET Core 框架深度集成的功能实现

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2-preview.1 145 12/4/2025
1.0.1 466 11/27/2025
1.0.0 453 11/25/2025
1.0.0-preview.5 92 10/24/2025