diff --git a/Yi.Abp.Net8/Yi.Abp.sln b/Yi.Abp.Net8/Yi.Abp.sln index 2c715929..d7d36b3d 100644 --- a/Yi.Abp.Net8/Yi.Abp.sln +++ b/Yi.Abp.Net8/Yi.Abp.sln @@ -70,7 +70,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Bbs.SqlSugarCo EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "audit-logging", "audit-logging", "{73CCF2C4-B9FD-44AB-8D4B-0A421805B094}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.AuditLogging.SqlSugarCore", "module\audit-logging\Yi.AuditLogging.SqlSugarCore\Yi.AuditLogging.SqlSugarCore.csproj", "{48806510-8E18-4E1E-9BAF-5B97E88C5FC3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.AuditLogging.SqlSugarCore", "module\audit-logging\Yi.AuditLogging.SqlSugarCore\Yi.AuditLogging.SqlSugarCore.csproj", "{48806510-8E18-4E1E-9BAF-5B97E88C5FC3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Authentication/QQAuthService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Authentication/QQAuthService.cs new file mode 100644 index 00000000..29695fdc --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Authentication/QQAuthService.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Quartz.Logging; +using Volo.Abp; +using Volo.Abp.DependencyInjection; + +namespace Yi.Framework.Bbs.Application.Services.Authentication +{ + public class QQAuthService : IRemoteService, ITransientDependency + { + private HttpContext HttpContext { get; set; } + private ILogger _logger; + public QQAuthService(IHttpContextAccessor httpContextAccessor, ILogger logger) + { + _logger = logger; + HttpContext = httpContextAccessor.HttpContext ?? throw new ApplicationException("未注册Http"); + } + [HttpGet("/auth/qq")] + public async Task AuthQQAsync() + { + var data = await HttpContext.AuthenticateAsync("QQ"); + _logger.LogError($"QQ回调信息:{Newtonsoft.Json.JsonConvert.SerializeObject(data)}"); + _logger.LogError($"QQ回调身份:{Newtonsoft.Json.JsonConvert.SerializeObject(data.Principal)}"); + } + } +} diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/Yi.Abp.Web.csproj b/Yi.Abp.Net8/src/Yi.Abp.Web/Yi.Abp.Web.csproj index a166b72c..c033cb27 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/Yi.Abp.Web.csproj +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/Yi.Abp.Web.csproj @@ -4,6 +4,7 @@ + diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs index c8633dae..8ca75916 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs @@ -66,7 +66,7 @@ namespace Yi.Abp.Web service.AddControllers().AddNewtonsoftJson(options => { options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; - options.SerializerSettings.Converters.Add(new StringEnumConverter()); + options.SerializerSettings.Converters.Add(new StringEnumConverter()); }); Configure(options => @@ -103,33 +103,40 @@ namespace Yi.Abp.Web //jwt鉴权 var jwtOptions = configuration.GetSection(nameof(JwtOptions)).Get(); context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) - .AddJwtBearer(options => + .AddJwtBearer(options => + { + options.TokenValidationParameters = new TokenValidationParameters { - options.TokenValidationParameters = new TokenValidationParameters + ClockSkew = TimeSpan.Zero, + ValidateIssuer = true, + ValidateAudience = true, + ValidateLifetime = true, + ValidateIssuerSigningKey = true, + ValidIssuer = jwtOptions.Issuer, + ValidAudience = jwtOptions.Audience, + RequireExpirationTime = true, + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtOptions.SecurityKey)) + }; + options.Events = new JwtBearerEvents + { + OnMessageReceived = context => { - ClockSkew = TimeSpan.Zero, - ValidateIssuer = true, - ValidateAudience = true, - ValidateLifetime = true, - ValidateIssuerSigningKey = true, - ValidIssuer = jwtOptions.Issuer, - ValidAudience = jwtOptions.Audience, - RequireExpirationTime = true, - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtOptions.SecurityKey)) - }; - options.Events = new JwtBearerEvents - { - OnMessageReceived = context => + var accessToken = context.Request.Query["access_token"]; + if (!string.IsNullOrEmpty(accessToken)) { - var accessToken = context.Request.Query["access_token"]; - if (!string.IsNullOrEmpty(accessToken)) - { - context.Token = accessToken; - } - return Task.CompletedTask; + context.Token = accessToken; } - }; - }); + return Task.CompletedTask; + } + }; + }) + .AddQQ("QQ", options => + { + options.ClientId = configuration["qq:client"]; + options.ClientSecret = configuration["qq:key"]; + options.CallbackPath = "/qq"; + + }); //授权 context.Services.AddAuthorization(); @@ -153,7 +160,7 @@ namespace Yi.Abp.Web //swagger app.UseYiSwagger(); - + //请求处理 app.UseYiApiHandlinge();