- 新增二维码生成端点,自动检测局域网 IP,前端扫一扫即可打开网站 - 提取 IApiResponse 接口,ServiceRequestBinder 支持强类型请求 DTO 绑定 - FileStream 端点迁移至 AppEndpoints 统一注册,管道支持 FileStreamResponse 原始文件返回 - 文件库端点全面使用 MapGet<TService, TRequest> 泛型注册 - 移除 Avalonia-API/Extensions 中的业务端点文件,统一由 Services 层管理
62 lines
3.1 KiB
C#
62 lines
3.1 KiB
C#
using Avalonia_Services.Core;
|
|
using Avalonia_Services.Services.AuthService;
|
|
|
|
namespace Avalonia_Services.Endpoints
|
|
{
|
|
/// <summary>
|
|
/// 认证端点统一入口。端点定义在这里,宿主项目只提供对应实现。
|
|
/// </summary>
|
|
public static class AuthEndpoints
|
|
{
|
|
/// <summary>
|
|
/// 配置 API 端鉴权端点(登录、刷新、登出)。
|
|
/// </summary>
|
|
/// <param name="builder">端点构建器。</param>
|
|
public static void ConfigureApi(ServiceEndpointBuilder builder)
|
|
{
|
|
builder.ConfigureEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapPost<IApiAuthEndpointService, ApiLoginRequest>("api/auth/login", (service, request, ctx) => service.LoginAsync(request, ctx))
|
|
.WithName("ApiLogin")
|
|
.WithOpenApi("Auth", "API 登录,返回 access token 和 refresh token。", "", typeof(ApiLoginRequest), typeof(AuthTokenResponse))
|
|
.ApiOnly();
|
|
|
|
endpoints.MapPost<IApiAuthEndpointService, ApiRefreshTokenRequest>("api/auth/refresh", (service, request, ctx) => service.RefreshAsync(request, ctx))
|
|
.WithName("ApiRefresh")
|
|
.WithOpenApi("Auth", "API refresh token 轮换。", "", typeof(ApiRefreshTokenRequest), typeof(AuthTokenResponse))
|
|
.ApiOnly();
|
|
|
|
endpoints.MapPost<IApiAuthEndpointService, ApiLogoutRequest>("api/auth/logout", (service, request, ctx) => service.LogoutAsync(request, ctx))
|
|
.WithName("ApiLogout")
|
|
.WithOpenApi("Auth", "API 退出登录并吊销 refresh token。", "", typeof(ApiLogoutRequest))
|
|
.ApiOnly();
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 配置 PC 端鉴权端点(授权码登录、刷新、登出)。
|
|
/// </summary>
|
|
/// <param name="builder">端点构建器。</param>
|
|
public static void ConfigurePc(ServiceEndpointBuilder builder)
|
|
{
|
|
builder.ConfigureEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapPost<IPcAuthEndpointService, PcAuthorizeRequest>("api/pc/auth/authorize", (service, request, ctx) => service.AuthorizeAsync(request, ctx))
|
|
.WithName("PcAuthorize")
|
|
.WithOpenApi("Auth", "PC 授权码登录,生成本地全局 token。", "", typeof(PcAuthorizeRequest), typeof(PcTokenResponse))
|
|
.PcOnly();
|
|
|
|
endpoints.MapPost<IPcAuthEndpointService, PcRefreshRequest>("api/pc/auth/refresh", (service, request, ctx) => service.RefreshAsync(request, ctx))
|
|
.WithName("PcRefresh")
|
|
.WithOpenApi("Auth", "PC 全局 token 刷新。", "", typeof(PcRefreshRequest), typeof(PcTokenResponse))
|
|
.PcOnly();
|
|
|
|
endpoints.MapPost<IPcAuthEndpointService, PcLogoutRequest>("api/pc/auth/logout", (service, request, ctx) => service.LogoutAsync(request, ctx))
|
|
.WithName("PcLogout")
|
|
.WithOpenApi("Auth", "PC 退出登录。", "", typeof(PcLogoutRequest))
|
|
.PcOnly();
|
|
});
|
|
}
|
|
}
|
|
}
|