OAuth2客户端应用程序使用Spring Boot 3.0.5和Retrofit。

huangapple go评论65阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年4月6日 22:27:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950682.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定