核心流程图(Token 颁发阶段)

🎯 常用扩展点说明(按流程顺序)
| 序号 | 扩展点 | 配置方式 | 典型用途 | 代码示例位置 |
|---|---|---|---|---|
| 1 | ClientDetailsService |
clients.withClientDetails(customService) |
从数据库、Redis 等动态加载客户端信息,支持客户端动态注册 | AuthorizationServerConfig.configure(ClientDetailsServiceConfigurer) |
| 2 | TokenGranter |
endpoints.tokenGranter(customGranter) |
自定义 grant_type(如短信验证码、手机号一键登录) | AuthorizationServerEndpointsConfigurer.tokenGranter() |
| 3 | UserDetailsService |
endpoints.userDetailsService(customService) |
自定义用户数据源(非默认的 loadUserByUsername) |
在 AuthorizationServerEndpointsConfigurer 中注入(你的代码中注释了该行) |
| 4 | AuthorizationCodeServices |
endpoints.authorizationCodeServices(customService) |
自定义授权码的存储方式(默认是内存,可改为 Redis、数据库) | AuthorizationServerEndpointsConfigurer.authorizationCodeServices() |
| 5 | TokenStore |
endpoints.tokenStore(customStore) |
自定义 Token 存储策略(Redis、JWT、JDBC) | AuthorizationServerEndpointsConfigurer.tokenStore() |
| 6 | TokenEnhancer |
endpoints.tokenEnhancer(customEnhancer) |
向 AccessToken 添加额外信息(如用户 ID、租户 ID),或生成 OIDC 的 id_token |
你代码中 @Bean TokenEnhancer |
| 7 | WebResponseExceptionTranslator |
endpoints.exceptionTranslator(customTranslator) |
统一异常响应的格式(例如统一返回 JSON 格式的错误信息) | AuthorizationServerEndpointsConfigurer.exceptionTranslator() |
📌 总结
-
核心流程 :从客户端请求
/oauth/token开始 → 客户端认证 → 用户认证(若需要)→ 生成原始 Token → Token 增强 → 存储 → 返回。 -
最常用的扩展点:
-
TokenStore:切换 JWT / Redis 存储。 -
TokenEnhancer:自定义 Token 内容。 -
ClientDetailsService:让客户端配置可动态管理。 -
WebResponseExceptionTranslator:美化异常响应。
-