如何使用 MicroProfile Rest Client 在 Quarkus Apps 中传播 Authorization 标头? [英] How can the Authorization header be propagated in Quarkus Apps with the MicroProfile Rest Client?

查看:41
本文介绍了如何使用 MicroProfile Rest Client 在 Quarkus Apps 中传播 Authorization 标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

当我使用 MicroProfile Rest Client(同步模式)调用第二个微服务时,缺少 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.Final 中嵌入的 MicroProfile 版本的问题吗?

谢谢!

解决方案

Phillip Krüger 回答了这个问题.需要添加的只是在另一个服务调用的服务中的这个设置.

resteasy.role.based.security=true

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

I have two microservices implemented with Quarkus 1.5.2.Final with endpoints that are protected with @RolesAllowed("user"). The endpoints work when I call them directly with a valid token.

When I use the MicroProfile Rest Client (synchronous mode) to invoke the second microservice, the Authorization header is missing.

According to the MicroProfile spec (https://download.eclipse.org/microprofile/microprofile-rest-client-1.3/microprofile-rest-client-1.3.html) the following setting should do the trick: org.eclipse.microprofile.rest.client.propagateHeaders=Authorization

However it doesn't work. I also tried these without success. "mp.rest.client.propagateHeaders=Authorization", "resteasy.role.based.security=true" and "quarkus.smallrye-jwt.enabled=true".

When I add the header manually to the Rest Client it works, but my understanding was this should be done automatically.

Do I do anything wrong or could this be an issue with the MicroProfile version embedded in Quarkus 1.5.2.Final?

Thanks!

解决方案

Phillip Krüger answered the question. All that needed to be added was this setting in the service which is invoked by another service.

resteasy.role.based.security=true

Code is here: https://github.com/IBM/cloud-native-starter/blob/d30b084eeddcebf793037bea07244fe20917caa3/security/articles-secure/src/main/resources/application.properties#L9

这篇关于如何使用 MicroProfile Rest Client 在 Quarkus Apps 中传播 Authorization 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆