如何使用MicroProfile Rest客户端在Quarkus Apps中传播Authorization标头?

时间:2020-07-02 08:08:31

标签: quarkus microprofile

我有两个用Quarkus 1.5.2。实现的微服务,最终的端点受@RolesAllowed(“ user”)保护。当我使用有效令牌直接调用端点时,它们会起作用。

当我使用MicroProfile Rest客户端(同步模式)调用第二个微服务时,缺少Authorization标头。

根据MicroProfile规范(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 Client时,它可以工作,但是我的理解是应该自动完成。

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

谢谢!

2 个答案:

答案 0 :(得分:1)

根据规范,要使mp.rest.client.propagateHeaders属性起作用,您需要在定义外部服务的接口上指定@RegisterClientHeaders

答案 1 :(得分:0)

PhillipKrüger回答了问题。需要添加的只是该设置,该设置由另一个服务调用。

resteasy.role.based.security = true

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