spring-boot - What is the difference between DefaultOAuth2AuthorizedClientManager and AuthorizedClientServiceOAuth2AuthorizedClientManager
问题描述
Looking at the documentation, the only recommendation I found is
The DefaultOAuth2AuthorizedClientManager is designed to be used within the context of a HttpServletRequest. When operating outside of a HttpServletRequest context, use AuthorizedClientServiceOAuth2AuthorizedClientManager instead.
I could test that WebClient
calls hang using the DefaultOAuth2AuthorizedClientManager
outside the scope of a servlet request, however, nothing weird happens if I use AuthorizedClientServiceOAuth2AuthorizedClientManager
inside the context of a servlet request. Then, what's the difference between the two of them?
解决方案
您从文档中指出的主要区别在于它们的使用位置。从外部看,这可能不太明显,但在框架内部会更明显。但也许解释它们为何不同的更简单方法是查看它们封装的内容。
DefaultOAuth2AuthorizedClientManager
使用一个OAuth2AuthorizedClientRepository
- 它的方法签名为
loadAuthorizedClient(String clientRegistrationId, Authentication principal, HttpServletRequest request)
- 它的方法签名为
AuthorizedClientServiceOAuth2AuthorizedClientManager
使用一个OAuth2AuthorizedClientService
- 它的方法签名为
loadAuthorizedClient(String clientRegistrationId, String principalName)
- 它的方法签名为
所以DefaultOAuth2AuthorizedClientManager
我猜你会称之为“基于请求”并且AuthorizedClientServiceOAuth2AuthorizedClientManager
是“基于服务”,这实际上只是意味着其他一切。
API 文档在这里会有所帮助:
更新:
将请求作为参数有什么附加价值?
作为一个接口,声明该loadAuthorizedClient
方法接受请求作为参数意味着任何未来的实现都可以使用请求来影响其决定。默认实现 ( DefaultOAuth2AuthorizedClientManager
) 执行此操作,因为它HttpSessionOAuth2AuthorizedClientRepository
利用请求来访问会话。
推荐阅读
- r - R Shiny 错误:警告:$ 中的错误:“闭包”类型的对象不是子集
- css - 每当有人选择文本时使用CSS,模糊除所选文本之外的所有文本?
- libgdx - LibGdx:在同一批次上渲染 Sprite 和 PolygonSprite?
- php - 将字段添加到 php-fpm-status-page
- jenkins - Jenkinsfile - 调用多个 groovy 脚本
- python - 使用ffmpeg为非连续图像到视频插入占位符帧?
- python - 熊猫:如何用一列的另一行创建一个列表?
- arrays - 记录数组定义
- javascript - 如何在底部组件上注册鼠标移动?
- sql - 将一些类别作为列名