diff --git a/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.Host/appsettings.Development.json b/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.Host/appsettings.Development.json index 503b04b7a..5fa543474 100644 --- a/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.Host/appsettings.Development.json +++ b/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.Host/appsettings.Development.json @@ -43,7 +43,7 @@ } }, "AuthServer": { - "Host": "http://localhost:44385/",//填写你的IdentityServer服务器地址 + "Authority": "http://localhost:44385/",//填写你的IdentityServer服务器地址 "ApiName": "apigateway-service",//填写你的IdentityServer服务器注册的ApiName "ApiSecret": "defj98734htgrb90365D23"//填写你的IdentityServer服务器注册的ApiSecret }, diff --git a/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json b/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json index 1542e3bb5..bffda7073 100644 --- a/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json +++ b/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json @@ -28,7 +28,7 @@ } }, "AuthServer": { - "Host": "http://localhost:44385/", + "Authority": "http://localhost:44385/", "ApiName": "apigateway-service", "ApiSecret": "defj98734htgrb90365D23" }, diff --git a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs index c5e39f0c5..bff31156e 100644 --- a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs +++ b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs @@ -53,6 +53,9 @@ using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.TenantManagement.EntityFrameworkCore; using Volo.Abp.Threading; using Volo.Abp.VirtualFileSystem; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Volo.Abp.AspNetCore.Security.Claims; +using System.Collections.Generic; namespace LINGYUN.Abp.BackendAdmin { @@ -254,16 +257,17 @@ namespace LINGYUN.Abp.BackendAdmin new NameValue("en", "en")); }); - context.Services.AddAuthentication("Bearer") - .AddIdentityServerAuthentication(options => + Configure(options => + { + options.Maps.TryAdd("name", () => AbpClaimTypes.UserName); + }); + + context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => { options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = false; - options.ApiName = configuration["AuthServer:ApiName"]; - AbpClaimTypes.UserId = JwtClaimTypes.Subject; - AbpClaimTypes.UserName = JwtClaimTypes.Name; - AbpClaimTypes.Role = JwtClaimTypes.Role; - AbpClaimTypes.Email = JwtClaimTypes.Email; + options.Audience = configuration["AuthServer:ApiName"]; }); if (!hostingEnvironment.IsDevelopment()) diff --git a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/LINGYUN.Abp.BackendAdmin.HttpApi.Host.csproj b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/LINGYUN.Abp.BackendAdmin.HttpApi.Host.csproj index c5f279d35..3f3a1165f 100644 --- a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/LINGYUN.Abp.BackendAdmin.HttpApi.Host.csproj +++ b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/LINGYUN.Abp.BackendAdmin.HttpApi.Host.csproj @@ -31,7 +31,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs index 50c52a761..cead07a03 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs @@ -1,5 +1,6 @@ using DotNetCore.CAP; using LINGYUN.Abp.EventBus.CAP; +using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.Configuration; @@ -14,6 +15,7 @@ using System; using System.Text; using Volo.Abp; using Volo.Abp.AspNetCore; +using Volo.Abp.AspNetCore.Security.Claims; using Volo.Abp.Autofac; using Volo.Abp.AutoMapper; using Volo.Abp.Caching; @@ -21,6 +23,7 @@ using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.Http.Client.IdentityModel; using Volo.Abp.IdentityModel; using Volo.Abp.Modularity; +using Volo.Abp.Security.Claims; using Volo.Abp.Security.Encryption; namespace LINGYUN.ApiGateway @@ -70,13 +73,17 @@ namespace LINGYUN.ApiGateway Configure(configuration.GetSection("ApiGateway")); - context.Services.AddAuthentication("Bearer") - .AddIdentityServerAuthentication(options => + Configure(options => + { + options.Maps.TryAdd("name", () => AbpClaimTypes.UserName); + }); + + context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => { - options.Authority = configuration["AuthServer:Host"]; + options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = false; - options.ApiName = configuration["AuthServer:ApiName"]; - options.ApiSecret = configuration["AuthServer:ApiSecret"]; + options.Audience = configuration["AuthServer:ApiName"]; }); Configure(options => diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/LINGYUN.ApiGateway.Host.csproj b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/LINGYUN.ApiGateway.Host.csproj index 6a86fea62..52b2f50b4 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/LINGYUN.ApiGateway.Host.csproj +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/LINGYUN.ApiGateway.Host.csproj @@ -16,7 +16,7 @@ - + diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs index 9d97697a8..cc39316e7 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs @@ -1,8 +1,8 @@ using DotNetCore.CAP; -using IdentityModel; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.MultiTenancy.DbFinder; using LINGYUN.ApiGateway.EntityFrameworkCore; +using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; @@ -15,6 +15,7 @@ using StackExchange.Redis; using System; using System.Text; using Volo.Abp; +using Volo.Abp.AspNetCore.Security.Claims; using Volo.Abp.Autofac; using Volo.Abp.AutoMapper; using Volo.Abp.Caching; @@ -159,17 +160,17 @@ namespace LINGYUN.ApiGateway options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); }); - context.Services.AddAuthentication("Bearer") - .AddIdentityServerAuthentication(options => + Configure(options => + { + options.Maps.TryAdd("name", () => AbpClaimTypes.UserName); + }); + + context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => { - options.Authority = configuration["AuthServer:Host"]; + options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = false; - options.ApiName = configuration["AuthServer:ApiName"]; - options.ApiSecret = configuration["AuthServer:ApiSecret"]; - AbpClaimTypes.UserId = JwtClaimTypes.Subject; - AbpClaimTypes.UserName = JwtClaimTypes.Name; - AbpClaimTypes.Role = JwtClaimTypes.Role; - AbpClaimTypes.Email = JwtClaimTypes.Email; + options.Audience = configuration["AuthServer:ApiName"]; }); if (!hostingEnvironment.IsDevelopment()) diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj index a60e6c8bb..7f79cca0f 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj @@ -19,7 +19,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - @@ -27,6 +26,7 @@ + diff --git a/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs b/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs index 969264308..65fa73387 100644 --- a/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs +++ b/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs @@ -5,6 +5,7 @@ using LINGYUN.Abp.ExceptionHandling; using LINGYUN.Abp.ExceptionHandling.Emailing; using LINGYUN.Abp.MultiTenancy.DbFinder; using LINYUN.Abp.Sms.Aliyun; +using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; @@ -13,6 +14,7 @@ using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; using StackExchange.Redis; using System; @@ -21,6 +23,7 @@ using Volo.Abp; using Volo.Abp.Account; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; +using Volo.Abp.AspNetCore.Security.Claims; using Volo.Abp.Authorization.Permissions; using Volo.Abp.Autofac; using Volo.Abp.Caching; @@ -224,16 +227,17 @@ namespace LINGYUN.Abp.IdentityServer4 .AddVirtualJson("/LINGYUN/Abp/IdentityServer4/Localization"); }); - context.Services.AddAuthentication("Bearer") - .AddIdentityServerAuthentication(options => + Configure(options => + { + options.Maps.TryAdd("name", () => AbpClaimTypes.UserName); + }); + + context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => { options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = false; - options.ApiName = configuration["AuthServer:ApiName"]; - AbpClaimTypes.UserId = JwtClaimTypes.Subject; - AbpClaimTypes.UserName = JwtClaimTypes.Name; - AbpClaimTypes.Role = JwtClaimTypes.Role; - AbpClaimTypes.Email = JwtClaimTypes.Email; + options.Audience = configuration["AuthServer:ApiName"]; }); if (!hostingEnvironment.IsDevelopment()) diff --git a/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj b/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj index b55623fe4..1d92779d1 100644 --- a/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj +++ b/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj @@ -24,7 +24,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs index 23e793c75..c61d5540b 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs @@ -1,6 +1,5 @@ using DotNetCore.CAP; using Hangfire; -using IdentityModel; using LINGYUN.Abp.BackgroundJobs.Hangfire; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.ExceptionHandling; @@ -14,6 +13,7 @@ using LINGYUN.Abp.MessageService.MultiTenancy; using LINGYUN.Abp.MultiTenancy.DbFinder; using LINGYUN.Abp.Notifications.SignalR; using LINGYUN.Abp.Notifications.WeChat.WeApp; +using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.DataProtection; @@ -30,6 +30,7 @@ using System.Text; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.MultiTenancy; +using Volo.Abp.AspNetCore.Security.Claims; using Volo.Abp.Autofac; using Volo.Abp.Caching; using Volo.Abp.Caching.StackExchangeRedis; @@ -241,16 +242,17 @@ namespace LINGYUN.Abp.MessageService .AddVirtualJson("/Localization/HttpApiHost"); }); - context.Services.AddAuthentication("Bearer") - .AddIdentityServerAuthentication(options => + Configure(options => + { + options.Maps.TryAdd("name", () => AbpClaimTypes.UserName); + }); + + context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => { options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = false; - options.ApiName = configuration["AuthServer:ApiName"]; - AbpClaimTypes.UserId = JwtClaimTypes.Subject; - AbpClaimTypes.UserName = JwtClaimTypes.Name; - AbpClaimTypes.Role = JwtClaimTypes.Role; - AbpClaimTypes.Email = JwtClaimTypes.Email; + options.Audience = configuration["AuthServer:ApiName"]; }); if (!hostingEnvironment.IsDevelopment()) diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj index b6db5625a..33c49446a 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj @@ -24,7 +24,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs index 18a7d914b..5dde3c123 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs @@ -1,5 +1,4 @@ using DotNetCore.CAP; -using IdentityModel; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.ExceptionHandling; using LINGYUN.Abp.ExceptionHandling.Emailing; @@ -9,6 +8,7 @@ using LINGYUN.Abp.Notifications; using LINGYUN.Platform.EntityFrameworkCore; using LINGYUN.Platform.HttpApi; using LINGYUN.Platform.MultiTenancy; +using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; @@ -25,6 +25,7 @@ using System.Text; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.MultiTenancy; +using Volo.Abp.AspNetCore.Security.Claims; using Volo.Abp.Autofac; using Volo.Abp.BlobStoring; using Volo.Abp.BlobStoring.FileSystem; @@ -219,29 +220,19 @@ namespace LINGYUN.Platform { options.Languages.Add(new LanguageInfo("en", "en", "English")); options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); + }); - options - .AddLanguagesMapOrUpdate( - "vue-admin-element-ui", - new NameValue("zh-Hans", "zh"), - new NameValue("en", "en")); - options - .AddLanguageFilesMapOrUpdate( - "vue-admin-element-ui", - new NameValue("zh-Hans", "zh"), - new NameValue("en", "en")); + Configure(options => + { + options.Maps.TryAdd("name", () => AbpClaimTypes.UserName); }); - context.Services.AddAuthentication("Bearer") - .AddIdentityServerAuthentication(options => + context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => { options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = false; - options.ApiName = configuration["AuthServer:ApiName"]; - AbpClaimTypes.UserId = JwtClaimTypes.Subject; - AbpClaimTypes.UserName = JwtClaimTypes.Name; - AbpClaimTypes.Role = JwtClaimTypes.Role; - AbpClaimTypes.Email = JwtClaimTypes.Email; + options.Audience = configuration["AuthServer:ApiName"]; }); if (!hostingEnvironment.IsDevelopment()) diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj index 38a0cb22c..d2105ab14 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj @@ -28,7 +28,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive -