请求正文中的 Spring Boot Keycloak 客户端凭据

Posted

技术标签:

【中文标题】请求正文中的 Spring Boot Keycloak 客户端凭据【英文标题】:Spring Boot Keycloak Client Credentials in request body 【发布时间】:2021-12-16 21:57:03 【问题描述】:

我有一个应用程序使用 Keycloak Spring Boot Starter 并与 Keycloak 的自定义变体进行通信以生成令牌。问题是应用程序以标准方式在请求标头 (ClienIdAndClientCredentialsProvider) 中发送客户端凭据。我希望在请求正文中发送客户端凭据,而不是因为 Keycloak 的自定义变体期望它在请求正文中。

有没有办法做到这一点?

【问题讨论】:

参考我尝试过的任何东西:***.com/questions/69802099/… 【参考方案1】:

src/main/resources/META-INF/services 下创建一个名为org.keycloak.adapters.authentication.ClientCredentialsProvider 的文件,其内容:

com.whatever.app.CustomClientCredentialsProvider

application.properties 文件中修改如下:

// Provider names should be same as PROVIDER_ID and not be existing like secret, jwt, etc
keycloak.credentials.custom=xxxxx
keycloak.credentials.provider=custom

在您的CustomClientCredentialsProvider 中更改以下行:

public static final String PROVIDER_ID = "custom";

【讨论】:

以上是关于请求正文中的 Spring Boot Keycloak 客户端凭据的主要内容,如果未能解决你的问题,请参考以下文章

没有请求正文的对象的 Spring Boot RestClient 发布导致错误请求

如何在 spring-boot Web 客户端中发送请求正文?

从请求正文 Spring Boot 中删除空属性

Spring Boot RestController - PostMapping - 将请求正文作为 InputStream [重复]

正文中的 Spring Boot OAuth2RestTemplate 客户端凭据

如何在请求正文 Spring Boot Rest Controller 中指定订单验证