• ABP 6.0.0-rc.1的新特性


      2022-07-26官方发布ABP 6.0.0-rc.1版本,本文挑选了几个新特性进行了介绍,主要包括LeptonX Lite默认主题、OpenIddict模块,以及如何将Identity Server迁移到OpenIddict。据ABP官方公众号介绍,ABP 6.0.0稳定版的计划发布日期为2022-09-06,具体以实际发布日期为准。

    一.LeptonX Lite默认主题

      LeptonX Lite算是LeptonX Theme的一个简单实现,使用的是Razor Pages技术,而LeptonX Theme在ABP的商业版中有着完整的实现[17]。以前在ABP的MVC启动模板中,使用的是基本主题[18],而ABP 6.0.0-rc.1把LeptonX Lite作为默认主题[19]。

    1.基本主题

    基本主题的样子如下:

      基本主题在使用的时候都安装了哪些包呢?主要是在Web项目中需要安装Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic包,同时在模块类中需要依赖AbpAspNetCoreMvcUiBasicThemeModule模块,安装npm install @abp/aspnetcore.mvc.ui.theme.basic,运行abp install-libs。在wwwroot/styles中自定义global-styles.css文件,并且把该文件配置在模块的ConfigureServices()方法中:

    Configure(options =>
    {
        options.StyleBundles.Configure(BasicThemeBundles.Styles.Global, bundle =>
        {
            bundle.AddFiles("/styles/global-styles.css");
        });
    });
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    2.LeptonX Lite主题

      LeptonX Lite的样子如下:

    LeptonX Lite主题在使用的时候和基本主题差不多,差异如下:
    (1)更新或安装CLI

    dotnet tool update Volo.Abp.Cli -g --version 6.0.0-rc.1
    dotnet tool install Volo.Abp.Cli -g --version 6.0.0-rc.1
    
    • 1
    • 2

    (2)安装包

    dotnet add package Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite --prerelease
    
    • 1

    说明:务必加上这个–prerelease选项。
    (3)依赖模块

    [DependsOn(
         // Remove BasicTheme module from DependsOn attribute
    -    typeof(AbpAspNetCoreMvcUiBasicThemeModule),
         
         // Add LeptonX Lite module to DependsOn attribute
    +    typeof(AbpAspNetCoreMvcUiLeptonXLiteThemeModule),
    )]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    (4)配置服务

    Configure(options =>
    {
        options.StyleBundles.Configure(
            // Remove following line
    -       BasicThemeBundles.Styles.Global,
            // Add following line instead
    +       LeptonXLiteThemeBundles.Styles.Global
            bundle =>
            {
                bundle.AddFiles("/global-styles.css");
            }
        );
    });
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

      ABP商业版的LeptonX Theme样子如下:

    说明:因为平时在开发中使用的前后端分离方式,所以对这块不做过多介绍,了解即可。如果感兴趣,可以深入的学习下Razor Pages、Blazor、Bootstrap、jQuery等技术。

    二.OpenIddict模块

      这次ABP 6.0.0-rc.1较大的一个变化就是开始使用OpenIddict代替IDS(IdentityServer),因为IDS要收费了。ABP封装的OpenIddict模块源码结构如下:

    1.将Demo项目运行起来

      在模块的app目录下有6个项目,重点关心的是OpenIddict.Demo.Server和OpenIddict.Demo.API,前者是集成模块的ABP应用,包含2个clients和1个scope。后者是使用authentication认证的ASP.NET Core API应用。配置好OpenIddict.Demo.Server的appsettings.json文件,然后启动OpenIddict.Demo.Server和OpenIddict.Demo.API项目。https://localhost:44303/api/claims接口如下:

      OpenIddict.Demo.Server项目启动后,生成的数据库OpenIddict-Demo-Server如下:

    2.Volo.Abp.OpenIddict模块


    4个Repository分别为:

    IOpenIddictApplicationRepository
    IOpenIddictScopeRepository
    IOpenIddictAuthorizationRepository
    IOpenIddictTokenRepository
    
    • 1
    • 2
    • 3
    • 4

    4个Store分别为:

    IOpenIddictApplicationStore
    IOpenIddictScopeStore
    IOpenIddictAuthorizationStore
    IOpenIddictTokenStore
    
    • 1
    • 2
    • 3
    • 4

      Repository和Store的关系是什么呢?就是在Store中可以使用Repository来操作上述4种实体。从数据表上看,觉得OpenIddict相对于IDS4还是简单的,继续深入研究OpenIddict可以参考相关资源[6]-[15][21]。
      另外讲下怎么将OpenIddict模块运行起来,因为ABP中的模块在依赖其它项目的时候,都使用的源码依赖,将项目依赖(ProjectReference)修改为包依赖(PackageReference)即可。修改后的OpenIddict模块源码下载链接[23]。

    三.MAUI启动模板

      ABP 6.0.0-rc.1版本的CLI还不支持通过MAUI模板来创建项目,应该要到ABP 6.0.0版本了:

    四.将Identity Server迁移到OpenIddict[10]

    1.OpenIddict默认授权服务

      从ABP 6.0.0版本起,在ABP的启动模板中默认使用OpenIddict作为授权服务,ABP应该会一直支持IDS的,ABP7.0将基于.NET7,如果IDS支持.NET7,那么ABP也会继续跟进的。但是ABP不会支持商业版本的Duende IDS[22]。

    2.IDS迁移OpenIddict步骤

    (1)将所有Volo的软件包更新为6.x
    (2)使用相应的OpenIddict.*包替换VoloIdentityServer.*包。比如,Volo.Abp.IdentityServer.DomainVolo.Abp.OpenIddict.DomainVolo.Abp.Account.Web.IdentityServerVolo.Abp.Account.Web.OpenIddict
    (3)使用相应的OpenIddict模块替换所有IdentityServer模块。比如,AbpIdentityServerDomainModuleAbpOpenIddictDomainModuleAbpAccountWebIdentityServerModuleAbpAccountWebOpenIddictModule
    (4)在ProjectNameDbContext类中,重命名ConfigureIdentityServerConfigureOpenIddict
    (5)在UseAuthentication后,删除UseIdentityServer,添加UseAbpOpenIddictValidation
    (6)在启动模块中添加如下代码:

    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        PreConfigure(builder =>
        {
            builder.AddValidation(options =>
            {
                options.AddAudiences("ProjectName"); //修改为实际项目的名字
                options.UseLocalServer();
                options.UseAspNetCore();
            });
        });
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    (7)如果项目不是单独的AuthServer,那么添加ForwardIdentityAuthenticationForBearer

    private void ConfigureAuthentication(ServiceConfigurationContext context)
    {
        context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
    }
    
    • 1
    • 2
    • 3
    • 4

    (8)将IdentityServerDataSeedContributorDomain项目中删除。
    (9)创建新版本的项目,并且与现有项目同名。
    (10)拷贝新项目的ProjectName.Domain\OpenIddict\OpenIddictDataSeedContributor.cs到项目中,并且基于ProjectName.DbMigrator\appsettings.json来更新appsettings.json,注意修改端口号。
    (11)如果在IndexModel中使用IClientRepository,那么拷贝新项目的Index.cshtml.csIndex.cs到项目中。
    (12)在AddAbpOpenIdConnect()方法中,更新scope的名字从roleroles
    (13)在HttpApi.Host项目中,删除options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
    (14)AuthServer不再要求JWT bearer authentication,需要删除它,比如AddJwtBearerUseJwtTokenMiddleware
    (15)在IDE中尝试编译项目,根据报错来删除和引用代码和命名空间。
    (16)如果使用EF Core作为DatabaseProvider,那么迁移和更新数据库。

    3.OpenIddict相关的模块包

    (1)开源版本

    Volo.Abp.OpenIddict.Domain (AbpOpenIddictDomainModule)
    Volo.Abp.OpenIddict.Domain.Shared (AbpOpenIddictDomainSharedModule)
    Volo.Abp.OpenIddict.EntityFrameworkCore (AbpOpenIddictEntityFrameworkCoreModule)
    Volo.Abp.OpenIddict.AspNetCore (AbpOpenIddictAspNetCoreModule)
    Volo.Abp.OpenIddict.MongoDB (AbpOpenIddictMongoDbModule)
    Volo.Abp.Account.Web.OpenIddict (AbpAccountWebOpenIddictModule)
    Volo.Abp.PermissionManagement.Domain.OpenIddict (AbpPermissionManagementDomainOpenIddictModule)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    (2)商业版本

    Volo.Abp.OpenIddict.Pro.Application.Contracts (AbpOpenIddictProApplicationContractsModule)
    Volo.Abp.OpenIddict.Pro.Application (AbpOpenIddictProApplicationModule)
    Volo.Abp.OpenIddict.Pro.HttpApi.Client (AbpOpenIddictProHttpApiClientModule)
    Volo.Abp.OpenIddict.Pro.HttpApi (AbpOpenIddictProHttpApiModule)
    Volo.Abp.OpenIddict.Pro.Blazor(AbpOpenIddictProBlazorModule)
    Volo.Abp.OpenIddict.Pro.Blazor.Server (AbpOpenIddictProBlazorServerModule)
    Volo.Abp.OpenIddict.Pro.Blazor.WebAssembly (AbpOpenIddictProBlazorWebAssemblyModule)
    Volo.Abp.OpenIddict.Pro.Web (AbpOpenIddictProWebModule)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    五.ABP的路线图

      貌似进展比较慢,特别是Vue启动模板,千呼万唤都出不来。不过似乎也不重要了,GitHub上面有很多的基于Vue的前端框架,比如vue-element-admin就不错:

    参考文献:
    [1]ABP v5.3.3和6.0.0-rc.1比较改变:https://github.com/abpframework/abp/compare/5.3.3…6.0.0-rc.1
    [2]ABP路线图:https://docs.abp.io/zh-Hans/abp/latest/Road-Map
    [3]ABP 6.0.0-rc.1最近发布日志:https://github.com/abpframework/abp/releases
    [4]ABP.IO Platform 6.0 RC Has Been Published:https://blog.abp.io/abp/ABP.IO-Platform-6.0-RC-Has-Been-Published
    [5]ABP框架功能:https://abp.io/features
    [6]Add OpenIddict module:https://github.com/abpframework/abp/pull/12084
    [7]ABP OpenIddict Modules:https://github.com/abpframework/abp/blob/dev/docs/en/Modules/OpenIddict.md
    [8]Announcement of plan to replace the IdentityServer:https://github.com/abpframework/abp/issues/11989
    [9]ABP OpenIddict Modules:https://docs.abp.io/zh-Hans/abp/6.0/Modules/OpenIddict
    [10]Migration Identity Server to OpenIddict Guide:https://docs.abp.io/en/abp/6.0/Migration-Guides/IdentityServer_To_OpenIddict
    [11]OpenIddict:https://github.com/openiddict
    [12]OpenIddict官方文档:https://documentation.openiddict.com/
    [13]openiddict/openiddict-core:https://github.com/openiddict/openiddict-core
    [14]openiddict/openiddict-samples:https://github.com/openiddict/openiddict-samples
    [15]openiddict/openiddict-documentation:https://github.com/openiddict/openiddict-documentation

    [16]Integrated MAUI application startup template:https://github.com/abpframework/abp/pull/12962
    [17]LeptonX Theme:https://x.leptontheme.com/
    [18]ASP.NET Core MVC/Razor Pages: The Basic Theme:https://docs.abp.io/en/abp/latest/UI/AspNetCore/Basic-Theme
    [19]LeptonX Lite MVC UI:https://docs.abp.io/en/abp/latest/Themes/LeptonXLite/AspNetCore
    [20]ASP.NET Core MVC/Razor Pages: UI Theming:https://docs.abp.io/en/abp/latest/UI/AspNetCore/Theming
    [21]abp-samples/Ids2OpenId:https://github.com/abpframework/abp-samples/tree/master/Ids2OpenId
    [22]Fair Trade Software License:https://blog.duendesoftware.com/posts/20220111_fair_trade
    [23]修改后的OpenIddict模块源码:https://url39.ctfile.com/f/2501739-633476836-599209?p=2096 (访问密码: 2096)

  • 相关阅读:
    (自我介绍范文)java面试自我介绍
    系统平台搭建细节
    5. 内部类
    Spring Boot整合Spring Fox生成Swagger文档
    自定义异常、实际应用中的经验总结
    【云原生 | Kubernetes 系列】K8s 实战 Kubernetes 声明式对象的 增 删 改 查
    springboot基于Android的洗衣店预约APP毕业设计源码260839
    如何实现安卓屏幕分享及视频聊天?(源码)
    fslmaths/fslstats/fslmeants
    冻结ResNet50前几层并进行迁移学习(PyTorch)
  • 原文地址:https://blog.csdn.net/shengshengwang/article/details/126205814