diff --git a/docs/en/Dynamic-Claims.md b/docs/en/Dynamic-Claims.md index e56be09be8..3a2ef3ee58 100644 --- a/docs/en/Dynamic-Claims.md +++ b/docs/en/Dynamic-Claims.md @@ -38,12 +38,8 @@ Then add the `DynamicClaims` middleware. ````csharp public override void OnApplicationInitialization(ApplicationInitializationContext context) { - //... - app.UseAuthentication(); - - // Add this line after UseAuthentication + // Add this line before UseAuthorization. app.UseDynamicClaims(); - app.UseAuthorization(); //... } @@ -68,6 +64,8 @@ This implementation is used for the `Tiered` solution. It will get the dynamic c If you want to add your own dynamic claims contributor, you can a class that implement the `IAbpDynamicClaimsPrincipalContributor` interface. The framework will call the `ContributeAsync` method when get the dynamic claims. +> It better to use cache to improve performance. + ## AbpClaimsPrincipalFactoryOptions * `IsDynamicClaimsEnabled`: Enable or disable the dynamic claims feature. diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server.Mongo/MyProjectNameModule.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server.Mongo/MyProjectNameModule.cs index faf7121dfc..dc30b3568d 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server.Mongo/MyProjectNameModule.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server.Mongo/MyProjectNameModule.cs @@ -47,6 +47,7 @@ using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.Blazor.Server; using Volo.Abp.TenantManagement.MongoDB; using Volo.Abp.OpenIddict; +using Volo.Abp.Security.Claims; using Volo.Abp.UI.Navigation; using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.Uow; @@ -174,6 +175,10 @@ public class MyProjectNameModule : AbpModule private void ConfigureAuthentication(ServiceConfigurationContext context) { context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme); + context.Services.Configure(options => + { + options.IsDynamicClaimsEnabled = true; + }); } private void ConfigureUrls(IConfiguration configuration) @@ -358,6 +363,7 @@ public class MyProjectNameModule : AbpModule } app.UseUnitOfWork(); + app.UseDynamicClaims(); app.UseAuthorization(); app.UseSwagger(); diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameModule.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameModule.cs index d73ba01a49..742f061fa4 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameModule.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameModule.cs @@ -49,6 +49,7 @@ using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.Blazor.Server; using Volo.Abp.TenantManagement.EntityFrameworkCore; using Volo.Abp.OpenIddict; +using Volo.Abp.Security.Claims; using Volo.Abp.UI.Navigation; using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.Validation.Localization; @@ -176,6 +177,10 @@ public class MyProjectNameModule : AbpModule private void ConfigureAuthentication(ServiceConfigurationContext context) { context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme); + context.Services.Configure(options => + { + options.IsDynamicClaimsEnabled = true; + }); } private void ConfigureUrls(IConfiguration configuration) @@ -374,6 +379,7 @@ public class MyProjectNameModule : AbpModule } app.UseUnitOfWork(); + app.UseDynamicClaims(); app.UseAuthorization(); app.UseSwagger(); diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server.Mongo/MyProjectNameHostModule.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server.Mongo/MyProjectNameHostModule.cs index 2f625c6d4e..f9043aae71 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server.Mongo/MyProjectNameHostModule.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server.Mongo/MyProjectNameHostModule.cs @@ -41,6 +41,7 @@ using Volo.Abp.Swashbuckle; using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.MongoDB; using Volo.Abp.OpenIddict; +using Volo.Abp.Security.Claims; using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.Uow; using Volo.Abp.VirtualFileSystem; @@ -160,6 +161,10 @@ public class MyProjectNameHostModule : AbpModule private void ConfigureAuthentication(ServiceConfigurationContext context) { context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme); + context.Services.Configure(options => + { + options.IsDynamicClaimsEnabled = true; + }); } private void ConfigureBundles() @@ -312,6 +317,7 @@ public class MyProjectNameHostModule : AbpModule } app.UseUnitOfWork(); + app.UseDynamicClaims(); app.UseAuthorization(); app.UseSwagger(); diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server/MyProjectNameHostModule.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server/MyProjectNameHostModule.cs index e3e7afe999..65b09d8f09 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server/MyProjectNameHostModule.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server/MyProjectNameHostModule.cs @@ -43,6 +43,7 @@ using Volo.Abp.Swashbuckle; using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.EntityFrameworkCore; using Volo.Abp.OpenIddict; +using Volo.Abp.Security.Claims; using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.Uow; using Volo.Abp.VirtualFileSystem; @@ -163,6 +164,10 @@ public class MyProjectNameHostModule : AbpModule private void ConfigureAuthentication(ServiceConfigurationContext context) { context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme); + context.Services.Configure(options => + { + options.IsDynamicClaimsEnabled = true; + }); } private void ConfigureBundles() @@ -329,6 +334,7 @@ public class MyProjectNameHostModule : AbpModule } app.UseUnitOfWork(); + app.UseDynamicClaims(); app.UseAuthorization(); app.UseSwagger(); diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host.Mongo/MyProjectNameModule.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host.Mongo/MyProjectNameModule.cs index 7a99e10635..69f550112c 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host.Mongo/MyProjectNameModule.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host.Mongo/MyProjectNameModule.cs @@ -41,6 +41,7 @@ using Volo.Abp.Swashbuckle; using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.MongoDB; using Volo.Abp.OpenIddict; +using Volo.Abp.Security.Claims; using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.Uow; using Volo.Abp.Validation.Localization; @@ -162,6 +163,10 @@ public class MyProjectNameModule : AbpModule private void ConfigureAuthentication(ServiceConfigurationContext context) { context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme); + context.Services.Configure(options => + { + options.IsDynamicClaimsEnabled = true; + }); } private void ConfigureBundles() @@ -354,6 +359,7 @@ public class MyProjectNameModule : AbpModule } app.UseUnitOfWork(); + app.UseDynamicClaims(); app.UseAuthorization(); app.UseSwagger(); diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host/MyProjectNameModule.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host/MyProjectNameModule.cs index 6705902ed4..91218e4f0f 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host/MyProjectNameModule.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host/MyProjectNameModule.cs @@ -44,6 +44,7 @@ using Volo.Abp.Swashbuckle; using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.EntityFrameworkCore; using Volo.Abp.OpenIddict; +using Volo.Abp.Security.Claims; using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.Validation.Localization; using Volo.Abp.VirtualFileSystem; @@ -165,6 +166,10 @@ public class MyProjectNameModule : AbpModule private void ConfigureAuthentication(ServiceConfigurationContext context) { context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme); + context.Services.Configure(options => + { + options.IsDynamicClaimsEnabled = true; + }); } private void ConfigureBundles() @@ -371,6 +376,7 @@ public class MyProjectNameModule : AbpModule } app.UseUnitOfWork(); + app.UseDynamicClaims(); app.UseAuthorization(); app.UseSwagger(); diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc.Mongo/MyProjectNameModule.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc.Mongo/MyProjectNameModule.cs index 6e702fd36c..6117aafd5d 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc.Mongo/MyProjectNameModule.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc.Mongo/MyProjectNameModule.cs @@ -43,6 +43,7 @@ using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.MongoDB; using Volo.Abp.TenantManagement.Web; using Volo.Abp.OpenIddict; +using Volo.Abp.Security.Claims; using Volo.Abp.UI.Navigation; using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.Uow; @@ -167,6 +168,10 @@ public class MyProjectNameModule : AbpModule private void ConfigureAuthentication(ServiceConfigurationContext context) { context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme); + context.Services.Configure(options => + { + options.IsDynamicClaimsEnabled = true; + }); } private void ConfigureMultiTenancy() @@ -335,6 +340,7 @@ public class MyProjectNameModule : AbpModule } app.UseUnitOfWork(); + app.UseDynamicClaims(); app.UseAuthorization(); app.UseSwagger(); diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs index 43c60fc6a7..90f20f4325 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs @@ -45,6 +45,7 @@ using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.EntityFrameworkCore; using Volo.Abp.TenantManagement.Web; using Volo.Abp.OpenIddict; +using Volo.Abp.Security.Claims; using Volo.Abp.UI.Navigation; using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.Validation.Localization; @@ -169,6 +170,10 @@ public class MyProjectNameModule : AbpModule private void ConfigureAuthentication(ServiceConfigurationContext context) { context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme); + context.Services.Configure(options => + { + options.IsDynamicClaimsEnabled = true; + }); } private void ConfigureMultiTenancy() @@ -351,6 +356,7 @@ public class MyProjectNameModule : AbpModule } app.UseUnitOfWork(); + app.UseDynamicClaims(); app.UseAuthorization(); app.UseSwagger();