feat(auth): 添加统一 API 和 PC 认证端点
- 新增 API 端 JWT 登录、refresh token 轮换和退出登录流程 - 新增 refresh token 实体、DbSet 配置和 EF Core 迁移 - 新增 PC 端授权码登录、本地全局 token 刷新、登出和鉴权服务 - 扩展统一端点模型,支持宿主过滤、角色鉴权、OpenAPI 元数据和 DI 服务处理器 - API 启用 JwtBearer 认证、Swagger UI 和认证端点注册 - PC 端注册认证服务,并按宿主过滤桌面拦截端点
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
namespace Avalonia_Services.Services.AuthService
|
||||
{
|
||||
public sealed record ApiLoginRequest(string? Account, string? Password, string[]? Roles = null);
|
||||
|
||||
public sealed record ApiRefreshTokenRequest(string? RefreshToken);
|
||||
|
||||
public sealed record ApiLogoutRequest(string? RefreshToken);
|
||||
|
||||
public sealed record AuthTokenResponse(
|
||||
string AccessToken,
|
||||
string RefreshToken,
|
||||
DateTime AccessTokenExpiresAt,
|
||||
DateTime RefreshTokenExpiresAt,
|
||||
string[] Roles);
|
||||
|
||||
public sealed record PcAuthorizeRequest(string? AuthorizationCode);
|
||||
|
||||
public sealed record PcRefreshRequest(string? Token);
|
||||
|
||||
public sealed record PcLogoutRequest(string? Token);
|
||||
|
||||
public sealed record PcTokenResponse(string Token, DateTime ExpiresAt, string[] Roles);
|
||||
|
||||
public enum ThirdPartyAuthCheckResult
|
||||
{
|
||||
Valid,
|
||||
AuthorizationLost,
|
||||
TemporaryFailure,
|
||||
}
|
||||
|
||||
public interface IPcThirdPartyAuthorizationClient
|
||||
{
|
||||
Task<ThirdPartyAuthCheckResult> ValidateAuthorizationCodeAsync(string authorizationCode, CancellationToken cancellationToken = default);
|
||||
|
||||
Task<ThirdPartyAuthCheckResult> RefreshAuthorizationAsync(string authorizationReference, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Avalonia_Services.Core;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Avalonia_Services.Services.AuthService
|
||||
{
|
||||
public interface IApiAuthEndpointService
|
||||
{
|
||||
Task<object?> LoginAsync(ServiceEndpointContext ctx);
|
||||
|
||||
Task<object?> RefreshAsync(ServiceEndpointContext ctx);
|
||||
|
||||
Task<object?> LogoutAsync(ServiceEndpointContext ctx);
|
||||
}
|
||||
|
||||
public interface IPcAuthEndpointService
|
||||
{
|
||||
Task<object?> AuthorizeAsync(ServiceEndpointContext ctx);
|
||||
|
||||
Task<object?> RefreshAsync(ServiceEndpointContext ctx);
|
||||
|
||||
Task<object?> LogoutAsync(ServiceEndpointContext ctx);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user