如何使用 MicroProfile Rest 客户端在 Quarkus 应用程序中传播授权标头?

2024-02-14

我有两个使用 Quarkus 1.5.2.Final 实现的微服务,其端点受 @RolesAllowed("user") 保护。当我使用有效令牌直接调用端点时,端点可以工作。

当我使用 MicroProfile Rest Client(同步模式)调用第二个微服务时,授权标头丢失。

根据 MicroProfile 规范 (https://download.eclipse.org/microprofile/microprofile-rest-client-1.3/microprofile-rest-client-1.3.html https://download.eclipse.org/microprofile/microprofile-rest-client-1.3/microprofile-rest-client-1.3.html)以下设置应该可以解决问题: org.eclipse.microprofile.rest.client.propagateHeaders=授权

然而它不起作用。我也尝试过这些但没有成功。 “mp.rest.client.propagateHeaders=授权”、“resteasy.role.based.security=true”和“quarkus.smallrye-jwt.enabled=true”。

当我手动将标头添加到 Rest 客户端时,它可以工作,但我的理解是这应该自动完成。

我是否做错了什么,或者这可能是 Quarkus 1.5.2.Final 中嵌入的 MicroProfile 版本的问题吗?

Thanks!


菲利普·克鲁格回答了这个问题。需要添加的只是服务中由另一个服务调用的设置。

resteasy.role.based.security=true

代码在这里:https://github.com/IBM/cloud-native-starter/blob/d30b084eeddcebf793037bea07244fe20917caa3/security/articles-secure/src/main/resources/application.properties#L9 https://github.com/IBM/cloud-native-starter/blob/d30b084eeddcebf793037bea07244fe20917caa3/security/articles-secure/src/main/resources/application.properties#L9

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 MicroProfile Rest 客户端在 Quarkus 应用程序中传播授权标头? 的相关文章

随机推荐