export interface ResponseResult<T = unknown> {
    success: boolean;
    message?: string;
    code: number;
    data?: T;
}

export const WebAuthnErrorCodes = {
    PasskeyUserVerificationFailed: 40001,
} as const;

export interface AuthShellModel<TPayload = unknown> {
    entryName: "public" | "user" | "admin";
    pageName?: string;
    returnUrl?: string;
    message?: string;
    payload?: TPayload;
    user?: VmUserInfo;
}

export interface UserCenterPayload {
    webHost?: string;
}

export interface VmUserInfo {
    id: string;
    name: string;
    email?: string;
    sign?: string;
    avatar: string;
    permissions?: number;
    lastAccessTime?: string;
}

export interface AuthClientDisplayModel {
    clientId: string;
    displayName?: string;
    logo?: string;
    redirectUris: string[];
    scopes: string[];
}

export interface ConsentPayload {
    application: AuthClientDisplayModel;
    returnUrl?: string;
    authorizationRequestUri: string;
    authorizationParameters: Record<string, string[]>;
    scopes: string[];
}

export interface AccessDeniedPayload {
    application: AuthClientDisplayModel;
    returnUrl: string;
    hasPendingRequest: boolean;
}

export enum UserPermissions {
    System = 1 << 1,
    Member = 1 << 2,
}

export interface RedirectResult {
    redirectUrl: string;
}

export interface AuthSignInRequest {
    account?: string;
    password?: string;
    returnUrl?: string;
    pinCode?: string;
    remember: boolean;
    sessionInfo?: SessionMetadataPayload;
}

export interface SessionMetadataPayload {
    deviceName?: string;
    deviceType?: string;
    browserName?: string;
    browserVersion?: string;
    osName?: string;
    osVersion?: string;
    platform?: string;
    screenWidth?: number;
    screenHeight?: number;
    language?: string;
    latitude?: number;
    longitude?: number;
    locationAccuracy?: number;
    locationSource?: string;
}

export interface UserSecurityBindingStatus {
    hasTwoFactor: boolean;
    hasPasskey: boolean;
    requiresTwoFactor: boolean;
    requiresPasskey: boolean;
    hasRequiredSecurity: boolean;
    requiresSecurityOnboarding: boolean;
    isFullyBound: boolean;
}

export interface UserTwoFactorSetup {
    setupToken: string;
    account: string;
    manualEntryKey: string;
    qrCodeSetupImageUrl: string;
    setupUrl: string;
}

export interface WebAuthnCredentialViewModel {
    credentialId: string;
    displayName?: string;
    authenticatorAttachment?: string;
    createTime: string;
    lastUsedTime?: string;
}

export interface DeleteWebAuthnCredentialRequest {
    pinCode?: string;
    credential?: unknown;
    challenge?: string;
}

export interface DeleteWebAuthnCredentialResult {
    deleted: boolean;
    requiresVerification: boolean;
    verificationType?: "passkey" | "twoFactor";
    allowsTwoFactorFallback: boolean;
    assertionOptions?: PublicKeyCredentialRequestOptions;
    challenge?: string;
    needsSecuritySetup: boolean;
}

export interface AdminMfaPayload {
    pinCode?: string;
    credential?: unknown;
    challenge?: string;
}

export interface AdminMfaVerificationResult {
    requiresVerification: boolean;
    verificationType?: "passkey" | "twoFactor";
    allowsTwoFactorFallback: boolean;
    assertionOptions?: PublicKeyCredentialRequestOptions;
    challenge?: string;
    needsSecuritySetup: boolean;
}

/**
 * MFA 验证结果的结构化类型,兼容管理操作与 Passkey 删除两类接口返回
 */
export interface MfaVerificationInfo {
    requiresVerification: boolean;
    verificationType?: "passkey" | "twoFactor";
    allowsTwoFactorFallback?: boolean;
    assertionOptions?: PublicKeyCredentialRequestOptions;
    challenge?: string;
    needsSecuritySetup?: boolean;
}

export interface PagedListWarp<T> {
    currentPageIndex: number;
    pageSize: number;
    totalItemCount: number;
    totalPageCount: number;
    startItemIndex: number;
    endItemIndex: number;
    items: T[];
}

export interface AuthApplicationPageItem {
    id: string;
    clientId: string;
    displayName?: string;
    applicationType?: string;
    clientType?: string;
    redirectUris: string[];
    postLogoutRedirectUri?: string;
    logo?: string;
    permissions: string[];
}

export interface AuthAuthorizationPageItem {
    id: string;
    applicationId: string;
    applicationName: string;
    status?: string;
    statusName: string;
    type?: string;
    typeName: string;
    creationDate?: string;
    scopes: string[];
}

export interface AuthTokenPageItem {
    id: string;
    applicationId: string;
    applicationName?: string;
    authorizationId: string;
    creationDate?: string;
    expirationDate?: string;
    redemptionDate?: string;
    referenceId?: string;
    status?: string;
    statusName: string;
    subject?: string;
    type?: string;
    typeName: string;
}

export interface AuthAllowedClientItem {
    id: string;
    account: string;
    applicationId: string;
    applicationName?: string;
    allowedTime: string;
}

export type AccessRequestStatus = 0 | 1 | 2 | 3;

export interface AuthAccessRequestItem {
    id: string;
    userId: string;
    clientId: string;
    clientDisplayName?: string;
    status: AccessRequestStatus;
    reason?: string;
    requestTime: string;
    handleTime?: string;
    handlerId?: string;
    handlerName?: string;
    handleRemark?: string;
}
⚠⚠    以下内容为AI分析的结果,请根据实际情况进行判断。

代码解释

这是一个 TypeScript 类型定义文件,用于定义认证系统(Authentication System)的各种数据结构和接口。主要涵盖以下几个功能模块:

1. 基础响应结构

ResponseResult<T>
  • 通用 API 响应格式,包含成功状态、消息、状态码和泛型数据

2. 认证错误码

WebAuthnErrorCodes
  • 定义 WebAuthn(Passkey)相关错误码,目前包含用户验证失败

3. 页面外壳模型

AuthShellModel<TPayload>
  • 定义认证页面的入口类型(public/user/admin)
  • 包含页面名、返回 URL、消息、载荷数据和用户信息

4. 用户相关

VmUserInfo
  • 用户基本信息:ID、姓名、邮箱、签名、头像、权限等
UserPermissions
  • 使用位运算定义用户权限枚举(系统权限、成员权限)

5. OAuth/OIDC 授权流程

AuthClientDisplayModel
  • 客户端应用展示信息(Client ID、名称、Logo、重定向 URI、作用域)
ConsentPayload
  • 用户授权同意页面所需数据
AccessDeniedPayload
  • 访问拒绝页面数据

6. 登录认证

AuthSignInRequest
  • 登录请求参数:账号、密码、PIN 码、记住我、会话元数据等
SessionMetadataPayload
  • 会话元数据:设备信息、浏览器信息、操作系统、地理位置等

7. 多因素认证(MFA)

UserSecurityBindingStatus
  • 用户安全绑定状态:是否已配置双因素/Passkey、是否必须配置等
UserTwoFactorSetup
  • 双因素认证设置信息(TOTP):包含二维码、手动输入密钥等
WebAuthnCredentialViewModel
  • Passkey 凭证信息:凭证 ID、显示名称、创建时间、最后使用时间等

8. MFA 验证流程

DeleteWebAuthnCredentialRequest/Result
AdminMfaPayload/VerificationResult
MfaVerificationInfo
  • 处理删除 Passkey、管理员操作等场景的 MFA 验证
  • 支持 Passkey 或双因素认证验证
  • 包含是否需要验证、验证类型、WebAuthn 挑战参数等

9. 分页列表

PagedListWarp<T>
  • 通用分页包装器:当前页、页大小、总数、项目列表等

10. 管理后台数据模型

AuthApplicationPageItem
  • 应用列表项:Client ID、类型、重定向 URI、权限等
AuthAuthorizationPageItem
  • 授权记录列表项:关联应用、状态、类型、作用域等
AuthTokenPageItem
  • Token 列表项:关联应用/授权、创建/过期/兑换时间、状态等
AuthAllowedClientItem
  • 已授权客户端列表项
AuthAccessRequestItem
  • 访问请求记录:申请人、应用、状态(0-3)、处理人、处理时间等

总结

这是一个完整的认证授权系统的前端类型定义文件,支持:

  • 基于 OAuth/OIDC 的标准授权流程
  • 现代化的 Passkey(WebAuthn)认证
  • 传统双因素认证(TOTP)
  • 会话管理和安全审计
  • 完整的管理后台功能
评论加载中...