看看文档,我发现的唯一建议是
DefaultOAuth2AuthorizedClientManager设计为在HttpServletRequest上下文中使用。当在AuthorizedClientServiceOAuth2AuthorizedClientManager上下文之外操作时,请使用HttpServletRequest。
我可以使用servlet请求范围外的WebClient
来测试挂起的DefaultOAuth2AuthorizedClientManager
调用,但是,如果我在servlet请求的上下文中使用AuthorizedClientServiceOAuth2AuthorizedClientManager
,就不会发生什么奇怪的事情。那他们俩有什么区别?
发布于 2021-05-12 21:21:25
正如您从文档中注意到的,主要的区别在于它们将在何处使用。从外部来看,这一点可能不太明显,但在框架内部则更为明显。但是,解释它们为何不同的一个更简单的方法可能是查看它们封装的内容。
DefaultOAuth2AuthorizedClientManager
使用OAuth2AuthorizedClientRepository
loadAuthorizedClient(String clientRegistrationId, Authentication principal, HttpServletRequest request)
的方法签名。AuthorizedClientServiceOAuth2AuthorizedClientManager
使用OAuth2AuthorizedClientService
loadAuthorizedClient(String clientRegistrationId, String principalName)
的方法签名。因此,我猜DefaultOAuth2AuthorizedClientManager
是“基于请求的”,而AuthorizedClientServiceOAuth2AuthorizedClientManager
是“基于服务的”,这实际上意味着其他的一切。
API文档在这里会很有帮助:
更新:
将请求作为参数的附加值是什么?
作为接口,声明loadAuthorizedClient
方法接受请求作为参数意味着任何未来的实现都可以使用该请求来影响其决策。默认实现(DefaultOAuth2AuthorizedClientManager
)会这样做,因为HttpSessionOAuth2AuthorizedClientRepository
利用请求访问会话。
https://stackoverflow.com/questions/67500742
复制相似问题