添加允许通过外部源登录当前站点
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
{"neverMindDeployCard":true}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -123,6 +124,39 @@ public class DemoHttpApiHostModule : AbpModule
|
|||||||
private void ConfigureAuthentication(ServiceConfigurationContext context)
|
private void ConfigureAuthentication(ServiceConfigurationContext context)
|
||||||
{
|
{
|
||||||
context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
|
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 =>
|
context.Services.Configure<AbpClaimsPrincipalFactoryOptions>(options =>
|
||||||
{
|
{
|
||||||
options.IsDynamicClaimsEnabled = true;
|
options.IsDynamicClaimsEnabled = true;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<Import Project="..\..\common.props" />
|
<Import Project="..\..\common.props" />
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
<PackageReference Include="IdentityModel" Version="7.0.0" />
|
<PackageReference Include="IdentityModel" Version="7.0.0" />
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
|
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="9.0.0" />
|
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="10.0.1" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.0" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.0" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.0" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||||
|
|||||||
@@ -16,6 +16,12 @@
|
|||||||
"SwaggerClientId": "Demo_Swagger",
|
"SwaggerClientId": "Demo_Swagger",
|
||||||
"CertificatePassPhrase": "a8dad6bd-08cf-40f9-baaf-873686b50b75"
|
"CertificatePassPhrase": "a8dad6bd-08cf-40f9-baaf-873686b50b75"
|
||||||
},
|
},
|
||||||
|
"Authentication": {
|
||||||
|
"WeGit": {
|
||||||
|
"ClientId": "your-client-id",
|
||||||
|
"ClientSecret": "your-client-secret"
|
||||||
|
}
|
||||||
|
},
|
||||||
"StringEncryption": {
|
"StringEncryption": {
|
||||||
"DefaultPassPhrase": "xleACjIr9Lbh6yNy"
|
"DefaultPassPhrase": "xleACjIr9Lbh6yNy"
|
||||||
}}
|
}}
|
||||||
Reference in New Issue
Block a user