英文:
OAuth2 client app with Sping Boot 3.0.5 and Retrofit
问题
抱歉,我只能为您提供翻译。以下是翻译好的部分:
"Is there a way to access resources from a remote OAuth2 Resource server using a client OAuth2 spring boot application that uses Retrofit for calling the server? I'm using Spring Boot 3.0.5 and I'm not able to get the access token from the OAuth Authorization Server and use it with retrofit. It looks like the documentation is missing with the last versions of Sporing boot. Any hint? I need to get the access token from the Authorization Server and then get some resources from an OAuth2 Resource Server. It looks like I cannot find a working example for Spring Boot 2.0.5. With Postman is ok, I mean, I can get the access token and use it to call the endpoint but programmatically using Retrofit looks impossible."
英文:
Is there a way to access resources from a remote OAuth2 Resource server using a client OAuth2 spring boot application that uses Retrofit for calling the server ? I'm using Spring Boot 3.0.5 and I'm not able to get the access token from the OAuth Authorization Server and use it with retrofit. It looks like the documentation is missing with the last versions of Sporing boot. Any hint ? I need to get the access token from the Authorization Server and then get some resources from a OAuth2 Resource Server. It looks like I cannot find a working example for Spring boot 2.0.5. With Postman is ok, I mean, I can get the access token and use it to call the endpoint but programmatically using Retrofit looks impossible.
答案1
得分: 1
从Retrofit网站的标题中:
适用于Android和Java的类型安全的HTTP客户端
很明显,直接使用它,不应该期望与Spring有特定的集成...
你应该开始配置你的Spring应用程序作为OAuth2客户端(在Spring Boot中,只需要导入一些内容和设置一些属性)。
然后,要么:
-
使用
OAuth2AuthorizedClientRepository
检索授权客户端并手动编写与之相关的Retrofit配置(你将在这里找到特定客户端注册的令牌) -
使用比Retrofit更好地与Spring Boot集成的REST客户端,如Spring的响应式
WebClient
或Spring Cloud的@FeignClient
(后者类似于Retrofit,具有声明性特点)
英文:
From the Retrofit website header:
> A type-safe HTTP client for Android and Java
It is rather clear that, out of the box, you should not expect any particular integration with Spring...
What you should do start with is configuring your Spring application as an OAuth2 client (with Boot it's a matter of an import and a few properties).
Then either:
-
retrieve authorized client with
OAuth2AuthorizedClientRepository
and hand write Retrofit configuration with it (you'll find tokens for a specific client registration there) -
use a REST client that better integrates with boot than Retrofit like Spring's reactive
WebClient
or Spring Cloud@FeignClient
(the later being declarative like Retrofit)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论