【问题标题】:Spring WebClient with OAuth2 authorization具有 OAuth2 授权的 Spring WebClient
【发布时间】:2018-05-15 15:13:19
【问题描述】:

当使用旧 Spring 的 RestTemplate 与 OAuth 授权背后的某些 API 集成时,我正在做一些事情:

ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();resourceDetails.setClientId(oauthClientId);
resourceDetails.setClientSecret(oauthClientSecret);
resourceDetails.setAccessTokenUri(accessTokenUri);
// and we got the restTemplate:
OAuth2RestTemplate client = new OAuth2RestTemplate(resourceDetails);

然后 GET 如下:

client.getForEntity(restApiUri, MyEntity.class);

但它正在阻塞:(

作为一种解决方法,我使用 Mono.fromCallable(...) 包装了旧的 RestTempate。我还尝试使用 WebClient 做一些自定义客户端,它接受令牌并授权用户,然后对 RestApi 进行第二次调用。但这并不方便,因为令牌可能会过期,我必须实施更新过程。 OAuth 中可能还有更多我不知道的陷阱。

我如何使用 Spring web-flux 和 WebClient 以及 Mono/Flux 反应对象来做到这一点?

【问题讨论】:

标签: java spring spring-security oauth-2.0 spring-webflux


【解决方案1】:

也许this 会帮助你。关于配置 webclient 以按照您提到的方式使用它的中篇文章。

【讨论】:

    猜你喜欢
    • 2019-03-07
    • 2021-09-19
    • 2015-06-25
    • 2017-09-21
    • 2015-03-31
    • 2014-05-10
    • 2013-12-01
    • 1970-01-01
    • 2022-08-04
    相关资源
    最近更新 更多