Spring Authorization Server 0.2.3发布,放出联合身份DEMO
source link: https://segmentfault.com/a/1190000041612124
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
很快啊Spring Authorization Server又发新版本了,现在的版本是0.2.3。本次都有什么改动呢?我们来了解一下。
0.2.3版本特性
本次更新的新特性不少。
为公开客户端提供默认的设置
根据RFC6479,包含授权码(authorization_code
)授权并且客户端认证方式ClientAuthenticationMethod
只有一种,为none
的客户端都是公开(Public)客户端,反之就是机密(Confidential)客户端。
在0.2.3中,为公开的客户端提供了客户端默认配置ClientSettings
。
if (this.clientSettings == null) { ClientSettings.Builder builder = ClientSettings.builder(); if (isPublicClientType()) { // @formatter:off builder .requireProofKey(true) .requireAuthorizationConsent(true); // @formatter:on } this.clientSettings = builder.build(); }
这里多说点,公开客户端现在不单纯是authorization_code
模式授权,必须加上PKCE。
OAuth2ClientAuthenticationProvider被细分
Spring Authorization Server目前支持的客户端认证方式有:
client_secret_basic
client_secret_post
client_secret_jwt
private_key_jwt
none
之前由 OAuth2ClientAuthenticationProvider
一手包办,现在职责分离了。
JwtClientAssertionAuthenticationProvider
负责private_key_jwt
和client_secret_jwt
,具体细节请关注我的专栏。
目前胖哥已经实现了完整的private_key_jwt
认证的DEMO。
ClientSecretAuthenticationProvider
默认的client_secret_basic
和client_secret_post
由它负责。
PublicClientAuthenticationProvider
处理上面所说的公开客户端的认证方式。
InMemoryOAuth2AuthorizationService优化
主要优化了对未完成授权信息OAuth2Authorization
存储的淘汰策略,如果内存中存储的数量超过100
,会把最老存储的信息淘汰掉。
增加了联合身份的DEMO
Federated Identity Pattern (联合身份模式)举个例子,你同时对接了好几个身份提供商(IDP),你都需要跳不同的授权服务器页面并输入对应的密码,现在这些IDP可以都放在Spring Authorization Server下面,委托给Spring Authorization Server来处理身份认证授权。这样你不用跳来跳去了,只需要维护Spring Authorization Server中IDP的关系了。
请注意该功能不是Spring Authorization Server本身自带的功能。
OAuth2TokenGenerator
0.2.3抽象了OAuth2Token
的的生成模型:
@FunctionalInterface public interface OAuth2TokenGenerator<T extends OAuth2Token> { @Nullable T generate(OAuth2TokenContext context); }
OAuth2授权码使用统一的Token生成模型
授权码授权中的code
的生成现在也需要由OAuth2TokenGenerator
实现,实现类为OAuth2AuthorizationCodeGenerator
。
OAuth2刷新Token使用统一的Token生成模型
OAuth2刷新令牌 OAuth2RefreshToken
现在同样需要由OAuth2TokenGenerator
实现。
JWT的生成使用统一的模型
现在JWT的生成也由OAuth2TokenGenerator
来实现,具体的实现类为JwtGenerator
。
支持不透明令牌
现在你可以自定义一个OAuth2TokenGenerator
并注入到Spring IoC来实现自定义的令牌生成逻辑,这意味着不透明令牌也可以通过自定义来实现。
令牌自省过滤器配置现在可以自定义
0.2.3版本之前令牌自省的配置由 OAuth2AuthorizationServerConfigurer
负责,现在它由独立的配置类OAuth2TokenIntrospectionEndpointConfigurer
负责。
0.2.3也对部分的依赖进行了升级,具体为:
- 更新到Reactor 2020.0.16
- 更新到Spring Security 5.5.5
- 更新到Spring Framework 5.3.16
- 更新到Spring Boot 2.5.10
胖哥也将跟进变化,对依赖进行逐步升级。
关注公众号:Felordcn 获取更多资讯
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK