# 认证服务数据模型 **本文档引用的文件** - [ClientDto.cs](file://aspnet-core/modules/identityServer/LINGYUN.Abp.IdentityServer.Application.Contracts/LINGYUN/Abp/IdentityServer/Clients/Dto/ClientDto.cs) - [ApiResourceDto.cs](file://aspnet-core/modules/identityServer/LINGYUN.Abp.IdentityServer.Application.Contracts/LINGYUN/Abp/IdentityServer/ApiResources/Dto/ApiResourceDto.cs) - [IdentityResourceDto.cs](file://aspnet-core/modules/identityServer/LINGYUN.Abp.IdentityServer.Application.Contracts/LINGYUN/Abp/IdentityServer/IdentityResources/Dto/IdentityResourceDto.cs) - [ClientAppService.cs](file://aspnet-core/modules/identityServer/LINGYUN.Abp.IdentityServer.Application/LINGYUN/Abp/IdentityServer/Clients/ClientAppService.cs) - [IdentityServerMigrationsDbContextModelSnapshot.cs](file://aspnet-core/migrations/LY.MicroService.IdentityServer.EntityFrameworkCore/Migrations/IdentityServerMigrationsDbContextModelSnapshot.cs) ## 目录 1. [引言](#引言) 2. [核心实体设计](#核心实体设计) 3. [OAuth 2.0与OpenID Connect协议实现](#oauth-20与openid-connect协议实现) 4. [客户端认证配置](#客户端认证配置) 5. [授权范围管理](#授权范围管理) 6. [令牌生命周期管理](#令牌生命周期管理) 7. [实体关系图](#实体关系图) 8. [敏感信息存储策略](#敏感信息存储策略) 9. [扩展指导](#扩展指导) 10. [结论](#结论) ## 引言 本文档详细阐述了认证服务模块的数据模型设计,重点分析了客户端(Client)、API资源(ApiResource)和身份资源(IdentityResource)等核心实体。文档深入探讨了OAuth 2.0和OpenID Connect协议在数据模型中的体现,包括客户端认证配置、授权范围(Scope)管理以及令牌生命周期等关键数据设计。通过ER图展示实体间的关系,并说明了安全存储敏感信息的策略,为开发人员提供认证模型扩展的指导。 ## 核心实体设计 ### 客户端(Client)实体 客户端实体是认证服务的核心,代表了请求访问受保护资源的应用程序。该实体包含了客户端认证所需的所有配置信息。 **实体属性:** - **ClientId**: 客户端唯一标识符,用于在系统中识别客户端 - **ClientName**: 客户端名称,用于用户界面显示 - **Description**: 客户端描述信息 - **ClientUri**: 客户端主页URL - **LogoUri**: 客户端Logo的URL - **Enabled**: 客户端是否启用 - **ProtocolType**: 使用的协议类型(如oidc) - **RequireClientSecret**: 是否需要客户端密钥 - **RequireConsent**: 是否需要用户同意 - **AllowRememberConsent**: 是否允许记住用户同意 - **RequireRequestObject**: 是否需要请求对象 - **AllowedIdentityTokenSigningAlgorithms**: 允许的身份令牌签名算法 - **AlwaysIncludeUserClaimsInIdToken**: 是否始终在ID令牌中包含用户声明 - **RequirePkce**: 是否需要PKCE(Proof Key for Code Exchange) - **AllowPlainTextPkce**: 是否允许明文PKCE - **AllowAccessTokensViaBrowser**: 是否允许通过浏览器传输访问令牌 - **FrontChannelLogoutUri**: 前通道注销URL - **FrontChannelLogoutSessionRequired**: 前通道注销是否需要会话 - **BackChannelLogoutUri**: 后通道注销URL - **BackChannelLogoutSessionRequired**: 后通道注销是否需要会话 - **AllowOfflineAccess**: 是否允许离线访问 - **IdentityTokenLifetime**: 身份令牌生命周期(秒) - **AccessTokenLifetime**: 访问令牌生命周期(秒) - **AuthorizationCodeLifetime**: 授权码生命周期(