添加允许通过外部源登录当前站点

This commit is contained in:
ShaoHua
2025-12-29 01:18:14 +08:00
parent e2fc6b5d61
commit aea02022b4
4 changed files with 43 additions and 1 deletions
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -123,6 +124,39 @@ public class DemoHttpApiHostModule : AbpModule
private void ConfigureAuthentication(ServiceConfigurationContext context)
{
context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
var configuration = context.Services.GetConfiguration();
context.Services.AddAuthentication()
.AddOpenIdConnect("WeGit", "Login with WeGit", options =>
{
options.Authority = "https://git.we965.cn";
options.ClientId = configuration["Authentication:WeGit:ClientId"]!;
options.ClientSecret = configuration["Authentication:WeGit:ClientSecret"]!;
options.ResponseType = "code";
// Gitea specific scopes or defaults
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("email");
// Ensure HTTPS
options.RequireHttpsMetadata = true;
options.SaveTokens = true;
// Handle events if needed, e.g. mapping claims
options.Events.OnTokenValidated = async context =>
{
// You might need to map specific claims here if Gitea returns non-standard ones
await Task.CompletedTask;
};
// Bypass SSL certificate validation (DEV ONLY)
options.BackchannelHttpHandler = new System.Net.Http.HttpClientHandler
{
ServerCertificateCustomValidationCallback = System.Net.Http.HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
};
});
context.Services.Configure<AbpClaimsPrincipalFactoryOptions>(options =>
{
options.IsDynamicClaimsEnabled = true;