diff --git a/src/MicroserviceDemo/MicroserviceDemo.Web/MicroserviceDemo.Web.csproj b/src/MicroserviceDemo/MicroserviceDemo.Web/MicroserviceDemo.Web.csproj index ce06bc6d7a..84f03f39a3 100644 --- a/src/MicroserviceDemo/MicroserviceDemo.Web/MicroserviceDemo.Web.csproj +++ b/src/MicroserviceDemo/MicroserviceDemo.Web/MicroserviceDemo.Web.csproj @@ -25,9 +25,7 @@ - - diff --git a/src/MicroserviceDemo/MicroserviceDemo.Web/MicroservicesDemoWebModule.cs b/src/MicroserviceDemo/MicroserviceDemo.Web/MicroservicesDemoWebModule.cs index ba35973aff..8af1201e53 100644 --- a/src/MicroserviceDemo/MicroserviceDemo.Web/MicroservicesDemoWebModule.cs +++ b/src/MicroserviceDemo/MicroserviceDemo.Web/MicroservicesDemoWebModule.cs @@ -2,10 +2,10 @@ using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.OAuth.Claims; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Identity; +using Microsoft.Azure.KeyVault.WebKey; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -13,7 +13,6 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.IdentityModel.Tokens; using Swashbuckle.AspNetCore.Swagger; using Volo.Abp; -using Volo.Abp.Account.Web; using Volo.Abp.AspNetCore.Modularity; using Volo.Abp.AspNetCore.Mvc.Bundling; using Volo.Abp.Autofac; @@ -26,19 +25,16 @@ using Volo.Abp.Identity.Web; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy.Web; -using Volo.Abp.Permissions; using Volo.Abp.Permissions.EntityFrameworkCore; using Volo.Abp.Security.Claims; namespace MicroserviceDemo.Web { [DependsOn(typeof(AbpAutofacModule))] - [DependsOn(typeof(AbpHttpClientModule))] [DependsOn(typeof(AbpPermissionsEntityFrameworkCoreModule))] [DependsOn(typeof(AbpIdentityHttpApiModule))] [DependsOn(typeof(AbpIdentityWebModule))] [DependsOn(typeof(AbpIdentityEntityFrameworkCoreModule))] - [DependsOn(typeof(AbpAccountWebModule))] [DependsOn(typeof(AbpMultiTenancyHttpApiClientModule))] [DependsOn(typeof(AbpMultiTenancyWebModule))] public class MicroservicesDemoWebModule : AbpModule @@ -82,20 +78,17 @@ namespace MicroserviceDemo.Web "/Abp/ServiceProxyScript?_v=" + DateTime.Now.Ticks }); }); - - var xxx = JwtSecurityTokenHandler.DefaultInboundClaimTypeMap; - - //JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); //TODO: Try to understand if this is really needed? + + JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); services.AddAuthentication(options => { - //options.DefaultScheme = IdentityConstants.ApplicationScheme; - //options.DefaultChallengeScheme = "oidc"; + options.DefaultScheme = IdentityConstants.ApplicationScheme; + options.DefaultChallengeScheme = "oidc"; }) - //.AddCookie(IdentityConstants.ApplicationScheme) .AddOpenIdConnect("oidc", options => { - //options.SignInScheme = IdentityConstants.ApplicationScheme; + options.SignInScheme = IdentityConstants.ApplicationScheme; options.Authority = "http://localhost:54307"; options.RequireHttpsMetadata = false; @@ -109,13 +102,21 @@ namespace MicroserviceDemo.Web options.Scope.Add("openid"); options.Scope.Add("profile"); + options.Scope.Add("role"); options.Scope.Add("email"); options.Scope.Add("phone"); options.Scope.Add("multi-tenancy-api"); - options.Scope.Add("offline_access"); + //options.Scope.Add("offline_access"); + + options.ClaimActions.MapUniqueJsonKey("email_verified", "email_verified"); + options.ClaimActions.MapUniqueJsonKey("phone_number", "phone_number"); + options.ClaimActions.MapUniqueJsonKey("phone_number_verified", "phone_number_verified"); + options.ClaimActions.MapUniqueJsonKey("role", "role"); - options.ClaimActions.MapUniqueJsonKey(AbpClaimTypes.UserName, "name"); - options.ClaimActions.MapUniqueJsonKey(AbpClaimTypes.Email, "email"); + AbpClaimTypes.UserName = "name"; + AbpClaimTypes.Email = "email"; + AbpClaimTypes.Role = "role"; + AbpClaimTypes.UserId = "sub"; options.SecurityTokenValidator = new MyJwtSecurityTokenHandler(); }); diff --git a/src/MicroserviceDemo/MicroserviceDemo.Web/Pages/Index.cshtml b/src/MicroserviceDemo/MicroserviceDemo.Web/Pages/Index.cshtml index c92bb117dd..732d39e88e 100644 --- a/src/MicroserviceDemo/MicroserviceDemo.Web/Pages/Index.cshtml +++ b/src/MicroserviceDemo/MicroserviceDemo.Web/Pages/Index.cshtml @@ -21,9 +21,11 @@ @{ var accessToken = await HttpContextAccessor.HttpContext.GetTokenAsync("access_token"); + var refreshToken = await HttpContextAccessor.HttpContext.GetTokenAsync("refresh_token"); } - @accessToken
+ accessToken = @accessToken
+ refreshToken = @refreshToken
diff --git a/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs b/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs index 87b5c0b51f..6e2472e1a6 100644 --- a/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs +++ b/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; using Volo.Abp.AutoMapper; @@ -28,8 +29,6 @@ namespace Volo.Abp.Identity.Web public override void ConfigureServices(IServiceCollection services) { - services.AddAssemblyOf(); - services.Configure(options => { options.MenuContributors.Add(new AbpIdentityWebMainMenuContributor()); @@ -39,7 +38,7 @@ namespace Volo.Abp.Identity.Web { options.FileSets.AddEmbedded("Volo.Abp.Identity.Web"); }); - + services.Configure(options => { options.Resources.AddVirtualJson("en", "/Localization/Resources/AbpIdentity"); @@ -49,6 +48,18 @@ namespace Volo.Abp.Identity.Web { options.AddProfile(validate: true); }); + + services.Configure(options => + { + options.Conventions.AuthorizePage("/Identity/Users/Index", IdentityPermissions.Users.Default); + options.Conventions.AuthorizePage("/Identity/Users/CreateModal", IdentityPermissions.Users.Create); + options.Conventions.AuthorizePage("/Identity/Users/EditModal", IdentityPermissions.Users.Update); + options.Conventions.AuthorizePage("/Identity/Roles/Index", IdentityPermissions.Roles.Default); + options.Conventions.AuthorizePage("/Identity/Roles/CreateModal", IdentityPermissions.Roles.Create); + options.Conventions.AuthorizePage("/Identity/Roles/EditModal", IdentityPermissions.Roles.Update); + }); + + services.AddAssemblyOf(); } } } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs index 87036470bd..585b022b34 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs @@ -31,6 +31,7 @@ namespace Volo.Abp.IdentityServer AbpClaimTypes.UserId = JwtClaimTypes.Subject; AbpClaimTypes.UserName = JwtClaimTypes.Name; AbpClaimTypes.Role = JwtClaimTypes.Role; + AbpClaimTypes.Email = JwtClaimTypes.Email; } if (options.UpdateJwtSecurityTokenHandlerDefaultInboundClaimTypeMap) @@ -38,6 +39,7 @@ namespace Volo.Abp.IdentityServer JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.UserId] = AbpClaimTypes.UserId; JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.UserName] = AbpClaimTypes.UserName; JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.Role] = AbpClaimTypes.Role; + JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.Email] = AbpClaimTypes.Email; } return builder;