对接fake simple admin completed

This commit is contained in:
xiaolipro 2025-12-26 14:57:29 +08:00
parent 4c200cd1ff
commit 0ab0ed9adc
8 changed files with 14 additions and 87 deletions

6
Directory.Build.props Normal file
View File

@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<!-- All Fake packages -->
<FakePackageVersion>8.0.0</FakePackageVersion>
</PropertyGroup>
</Project>

View File

@ -18,6 +18,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution items", "solution
NuGet.Config = NuGet.Config
.gitignore = .gitignore
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
Global

View File

@ -1,30 +0,0 @@
using System.Text;
using Microsoft.IdentityModel.Tokens;
namespace TrackCenter.Api;
public class JWTEncryption
{
/// <summary>生成Token验证参数</summary>
/// <param name="jwtSettings"></param>
/// <returns></returns>
public static TokenValidationParameters CreateTokenValidationParameters(
JWTSettingsOptions jwtSettings)
{
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.SecretKey));
return new TokenValidationParameters()
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = jwtSettings.Issuer,
ValidAudience = jwtSettings.Audience,
IssuerSigningKey = key,
ClockSkew = TimeSpan.FromSeconds(jwtSettings.ClockSkewMinutes),
// 验证过期时间
RequireExpirationTime = true
};
}
}

View File

@ -1,41 +0,0 @@
namespace TrackCenter.Api;
/// <summary>Jwt 配置</summary>
public sealed class JWTSettingsOptions
{
/// <summary>
/// 配置节名称
/// </summary>
public static string SectionName = "JwtSettings";
/// <summary>
/// 密钥(至少32位字符)
/// </summary>
public string SecretKey { get; set; } = "YourSuperSecretKeyThatIsAtLeast32CharactersLong!";
/// <summary>
/// 签发者
/// </summary>
public string Issuer { get; set; } = "SimpleAdmin";
/// <summary>
/// 受众
/// </summary>
public string Audience { get; set; } = "SimpleAdminClient";
/// <summary>
/// Access Token 过期时间(分钟)
/// </summary>
public int ExpiryInMinutes { get; set; } = 60;
/// <summary>
/// Refresh Token 过期时间(天)
/// </summary>
public int RefreshExpiryInDays { get; set; } = 7;
/// <summary>
/// 时钟偏移(分钟),用于处理服务器时间差异
/// </summary>
public int ClockSkewMinutes { get; set; } = 5;
}

View File

@ -18,7 +18,7 @@
<ItemGroup>
<ProjectReference Include="..\TrackCenter.Application\TrackCenter.Application.csproj" />
<ProjectReference Include="..\TrackCenter.Repository\TrackCenter.Repository.csproj" />
<PackageReference Include="Fake.Autofac" Version="8.0.0-preview19" />
<PackageReference Include="Fake.Autofac" Version="8.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />

View File

@ -142,16 +142,7 @@ public class TrackCenterApiModule : FakeModule
});
});
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = "Bearer";
options.DefaultChallengeScheme = "Bearer";
}).AddJwtBearer(options =>
{
var jwtSettings = configuration.GetSection("JWTSettings").Get<JWTSettingsOptions>();
options.TokenValidationParameters = JWTEncryption.CreateTokenValidationParameters(jwtSettings);
});
services.AddFakeJwtAuthentication();
// 添加授权服务
services.AddAuthorization();

View File

@ -8,9 +8,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Fake.AspNetCore" Version="8.0.0-preview19" />
<PackageReference Include="Fake.EventBus.RabbitMQ" Version="8.0.0-preview19" />
<PackageReference Include="Fake.ObjectMapping.AutoMapper" Version="8.0.0-preview19" />
<PackageReference Include="Fake.AspNetCore" Version="8.0.0" />
<PackageReference Include="Fake.EventBus.RabbitMQ" Version="8.0.0" />
<PackageReference Include="Fake.ObjectMapping.AutoMapper" Version="8.0.0" />
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.14.1" />
<PackageReference Include="Confluent.Kafka" Version="2.10.0" />

View File

@ -9,11 +9,11 @@
<ItemGroup>
<PackageReference Include="NEST" Version="7.17.5" />
<PackageReference Include="Fake.SqlSugarCore" Version="8.0.0-preview19" />
<PackageReference Include="Fake.SqlSugarCore" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="4.3.0" />
<PackageReference Include="Fake.DomainDrivenDesign" Version="8.0.0-preview19" />
<PackageReference Include="Fake.DomainDrivenDesign" Version="8.0.0" />
</ItemGroup>
</Project>