Browse Source
Enable dynamic calims in `app nolayers`.
pull/18064/head
maliming
3 years ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
9 changed files with
51 additions and
5 deletions
docs/en/Dynamic-Claims.md
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server.Mongo/MyProjectNameModule.cs
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameModule.cs
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server.Mongo/MyProjectNameHostModule.cs
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server/MyProjectNameHostModule.cs
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host.Mongo/MyProjectNameModule.cs
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host/MyProjectNameModule.cs
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc.Mongo/MyProjectNameModule.cs
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs
@ -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.
@ -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 < AbpClaimsPrincipalFactoryOptions > ( 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 ( ) ;
@ -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 < AbpClaimsPrincipalFactoryOptions > ( 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 ( ) ;
@ -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 < AbpClaimsPrincipalFactoryOptions > ( options = >
{
options . IsDynamicClaimsEnabled = true ;
} ) ;
}
private void ConfigureBundles ( )
@ -312,6 +317,7 @@ public class MyProjectNameHostModule : AbpModule
}
app . UseUnitOfWork ( ) ;
app . UseDynamicClaims ( ) ;
app . UseAuthorization ( ) ;
app . UseSwagger ( ) ;
@ -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 < AbpClaimsPrincipalFactoryOptions > ( options = >
{
options . IsDynamicClaimsEnabled = true ;
} ) ;
}
private void ConfigureBundles ( )
@ -329,6 +334,7 @@ public class MyProjectNameHostModule : AbpModule
}
app . UseUnitOfWork ( ) ;
app . UseDynamicClaims ( ) ;
app . UseAuthorization ( ) ;
app . UseSwagger ( ) ;
@ -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 < AbpClaimsPrincipalFactoryOptions > ( options = >
{
options . IsDynamicClaimsEnabled = true ;
} ) ;
}
private void ConfigureBundles ( )
@ -354,6 +359,7 @@ public class MyProjectNameModule : AbpModule
}
app . UseUnitOfWork ( ) ;
app . UseDynamicClaims ( ) ;
app . UseAuthorization ( ) ;
app . UseSwagger ( ) ;
@ -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 < AbpClaimsPrincipalFactoryOptions > ( options = >
{
options . IsDynamicClaimsEnabled = true ;
} ) ;
}
private void ConfigureBundles ( )
@ -371,6 +376,7 @@ public class MyProjectNameModule : AbpModule
}
app . UseUnitOfWork ( ) ;
app . UseDynamicClaims ( ) ;
app . UseAuthorization ( ) ;
app . UseSwagger ( ) ;
@ -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 < AbpClaimsPrincipalFactoryOptions > ( options = >
{
options . IsDynamicClaimsEnabled = true ;
} ) ;
}
private void ConfigureMultiTenancy ( )
@ -335,6 +340,7 @@ public class MyProjectNameModule : AbpModule
}
app . UseUnitOfWork ( ) ;
app . UseDynamicClaims ( ) ;
app . UseAuthorization ( ) ;
app . UseSwagger ( ) ;
@ -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 < AbpClaimsPrincipalFactoryOptions > ( options = >
{
options . IsDynamicClaimsEnabled = true ;
} ) ;
}
private void ConfigureMultiTenancy ( )
@ -351,6 +356,7 @@ public class MyProjectNameModule : AbpModule
}
app . UseUnitOfWork ( ) ;
app . UseDynamicClaims ( ) ;
app . UseAuthorization ( ) ;
app . UseSwagger ( ) ;