Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ee297e819 | ||
|
|
bc4195e984 | ||
|
|
4a0caa1079 |
@@ -99,7 +99,7 @@ public class SimApiAuthGate(SimApiAuthGateClient simapi)
|
||||
public SimApiAuthGateDto.GetCodeResponse GetAuthCode(string? scene = null, Dictionary<string, object>? data = null,
|
||||
string? backUrl = null)
|
||||
{
|
||||
var code = simapi.SignQuery<string>("/api/auth/confirm/code",
|
||||
var code = simapi.SignQuery<string>("/api/auth/login/code",
|
||||
new { scene, data, backUrl });
|
||||
return new SimApiAuthGateDto.GetCodeResponse()
|
||||
{
|
||||
@@ -117,7 +117,7 @@ public class SimApiAuthGate(SimApiAuthGateClient simapi)
|
||||
/// <returns></returns>
|
||||
public SimApiAuthGateDto.AuthInfoResponse GetAuthInfo(string code, string? scene = null)
|
||||
{
|
||||
var resp = simapi.SignQuery<SimApiAuthGateDto.AuthInfoResponse>("/api/auth/confirm/get", new { code });
|
||||
var resp = simapi.SignQuery<SimApiAuthGateDto.AuthInfoResponse>("/api/auth/login/get", new { code });
|
||||
ErrorWhenNull(resp, 400232, "登录信息获取失败");
|
||||
ErrorWhen(resp.Scene != scene, 403003, "登录场景不匹配");
|
||||
return resp;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using SimApi.Configurations;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SimApi.Configurations;
|
||||
using SimApi.Helpers;
|
||||
|
||||
namespace SimApi.AuthGate;
|
||||
|
||||
public class SimApiAuthGateClient(SimApiOptions apiOptions) : SimApiHttpClient
|
||||
public class SimApiAuthGateClient(SimApiOptions apiOptions, ILogger<SimApiAuthGateClient> logger)
|
||||
: SimApiHttpClient(apiOptions, logger)
|
||||
{
|
||||
public override string Server { get; init; } = apiOptions.SimApiAuthGateOptions.Server ?? string.Empty;
|
||||
public override string AppId { get; init; } = apiOptions.SimApiAuthGateOptions.AppId ?? string.Empty;
|
||||
|
||||
@@ -11,4 +11,5 @@ public class SimApiAuthGateOptions
|
||||
/// 注意: 只有内部应用需要开启这个,也就是api通过内部网关代理后
|
||||
/// </summary>
|
||||
public bool UseMiddleware { get; set; }
|
||||
public bool UseIam { get; set; }
|
||||
}
|
||||
@@ -56,7 +56,6 @@ public class SimApiOptions
|
||||
/// </summary>
|
||||
public bool EnableSimApiResponseFilter { get; set; } = true;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 开启ForwardHeaders,开启后可以透传负载均衡的Headers
|
||||
/// default: true
|
||||
@@ -69,24 +68,17 @@ public class SimApiOptions
|
||||
/// </summary>
|
||||
public bool EnableLowerUrl { get; set; } = true;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 应用可以通过 /versions 显示出应用版本和SimApi包版本
|
||||
/// default: true
|
||||
/// </summary>
|
||||
public bool EnableVersionUrl { get; set; } = true;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 启用格式化的 Console Logger
|
||||
/// default: false
|
||||
/// </summary>
|
||||
public bool EnableLogger { get; set; } = true;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用SimApiHttpClient
|
||||
/// </summary>
|
||||
public bool EnableSimApiHttpClient { get; set; } = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 配置Job
|
||||
/// </summary>
|
||||
@@ -110,6 +102,13 @@ public class SimApiOptions
|
||||
|
||||
public SimApiExceptionOptions SimApiExceptionOptions { get; set; } = new();
|
||||
|
||||
public SimApiRouteOptions SimApiRouteOptions { get; set; } = new();
|
||||
|
||||
public void ConfigureSimApiRoute(Action<SimApiRouteOptions>? options = null)
|
||||
{
|
||||
options?.Invoke(SimApiRouteOptions);
|
||||
}
|
||||
|
||||
public void ConfigureSimApiException(Action<SimApiExceptionOptions>? options = null)
|
||||
{
|
||||
options?.Invoke(SimApiExceptionOptions);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SimApi.Configurations;
|
||||
|
||||
public class SimApiRouteOptions
|
||||
{
|
||||
public string? VersionRoute = "/versions";
|
||||
public string? LogoutRoute = "/auth/logout";
|
||||
public string? UserInfoRoute = "/user/info";
|
||||
}
|
||||
@@ -5,8 +5,6 @@ using SimApi.Helpers;
|
||||
|
||||
namespace SimApi.Controllers;
|
||||
|
||||
using static SimApiError;
|
||||
|
||||
public class SimApiAuthController(SimApiAuth auth) : SimApiBaseController
|
||||
{
|
||||
/// <summary>
|
||||
@@ -21,5 +19,11 @@ public class SimApiAuthController(SimApiAuth auth) : SimApiBaseController
|
||||
auth.Logout(value!);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取已登录用户信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost, SimApiAuth, SimApiDoc("认证", "获取已登录用户信息")]
|
||||
public SimApiLoginItem UserInfo() => LoginInfo;
|
||||
}
|
||||
@@ -31,11 +31,4 @@ public class SimApiCommonController : SimApiBaseController
|
||||
{ "App", SimApiUtil.AppVersion }
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取已登录用户信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/user/info"), SimApiAuth, SimApiDoc("认证", "获取已登录用户信息")]
|
||||
public SimApiLoginItem UserInfo() => LoginInfo;
|
||||
}
|
||||
+30
-9
@@ -333,7 +333,10 @@ public static class SimApiExtensions
|
||||
{
|
||||
builder.AddSingleton<SimApiAuthGateClient>();
|
||||
builder.AddSingleton<SimApiAuthGate>();
|
||||
builder.AddSingleton<SimApiIam>();
|
||||
if (simApiOptions.SimApiAuthGateOptions.UseIam)
|
||||
{
|
||||
builder.AddSingleton<SimApiIam>();
|
||||
}
|
||||
}
|
||||
|
||||
builder.AddSingleton(simApiOptions);
|
||||
@@ -440,17 +443,13 @@ public static class SimApiExtensions
|
||||
{
|
||||
logger.LogInformation("开始配置SimApiAuth...");
|
||||
builder.UseMiddleware<SimApiAuthMiddleware>();
|
||||
builder.MapControllerRoute(name: "Logout", pattern: "/auth/logout",
|
||||
defaults: new
|
||||
{
|
||||
controller = "SimApiAuth",
|
||||
action = "Logout"
|
||||
});
|
||||
}
|
||||
|
||||
if (options.EnableVersionUrl)
|
||||
|
||||
if (options.SimApiRouteOptions.VersionRoute != null)
|
||||
{
|
||||
builder.MapControllerRoute(name: "Versions", pattern: "/versions",
|
||||
logger.LogInformation("注册内置Route: Versions => {}", options.SimApiRouteOptions.LogoutRoute);
|
||||
builder.MapControllerRoute(name: "Versions", pattern: options.SimApiRouteOptions.VersionRoute,
|
||||
defaults: new
|
||||
{
|
||||
controller = "SimApiCommon",
|
||||
@@ -458,6 +457,28 @@ public static class SimApiExtensions
|
||||
});
|
||||
}
|
||||
|
||||
if (options.SimApiRouteOptions.UserInfoRoute != null)
|
||||
{
|
||||
logger.LogInformation("注册内置Route: UserInfo => {}", options.SimApiRouteOptions.UserInfoRoute);
|
||||
builder.MapControllerRoute(name: "UserInfo", pattern: options.SimApiRouteOptions.UserInfoRoute,
|
||||
defaults: new
|
||||
{
|
||||
controller = "SimApiAuth",
|
||||
action = "UserInfo"
|
||||
});
|
||||
}
|
||||
|
||||
if (options.SimApiRouteOptions.LogoutRoute != null)
|
||||
{
|
||||
logger.LogInformation("注册内置Route: Logout => {}", options.SimApiRouteOptions.LogoutRoute);
|
||||
builder.MapControllerRoute(name: "Logout", pattern: options.SimApiRouteOptions.LogoutRoute,
|
||||
defaults: new
|
||||
{
|
||||
controller = "SimApiAuth",
|
||||
action = "Logout"
|
||||
});
|
||||
}
|
||||
|
||||
if (options.EnableSimApiDoc)
|
||||
{
|
||||
logger.LogInformation("开始配置SimApiDoc...");
|
||||
|
||||
Reference in New Issue
Block a user