具有多个公钥的 MicroProfile JWT

发布于 2025-01-15 07:53:13 字数 559 浏览 5 评论 0原文

我想通过请求中作为授权标头提供的 JWT 来保护 REST API 的安全。我有一个 quarkus 应用程序,想使用他们的官方指南 - https://quarkus.io/guides /security-jwt

该指南指定:

mp.jwt.verify.publickey.location=publicKey.pem 
mp.jwt.verify.issuer=https://example.com/issuer

到目前为止一切顺利,现在我们可以检查 JWT 是否由与该公钥对应的私钥签名。我遇到的问题是我有不同的 API 和不同的 OAuth 集成,比方说 3。因此不同的 API 端点需要不同的 JWT,因此也有不同的公钥。 mp 是否支持此功能?

Spring Security 允许多个具有不同 @Order 的 WebSecurity 并在那里集成多个 oAuth 服务器。如何在 Quarkus/MP JAX-RS 中完成此操作?

I want to secure a REST API via JWTs provided as Authorization Header in the requests. I am have a quarkus application and would like to use their official guide - https://quarkus.io/guides/security-jwt

The guide specifies:

mp.jwt.verify.publickey.location=publicKey.pem 
mp.jwt.verify.issuer=https://example.com/issuer

So far so good, now we can check if JWTs are signed by a private key that corresponds to this public key. The problem I have is that I have different APIs and different OAuth integrations, let's say 3. So different API Endpoints expect different JWTs and hence also have different public keys. Is this even supported in mp?

Spring Security allows multiple WebSecurity with different @Order and integrating multiple oAuth Servers works there. How can this be done in Quarkus/MP JAX-RS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴梦一场 2025-01-22 07:53:13

是的。但是使用 JSON Jwt 密钥集

mp.jwt.verify.publickey.location=my-pubkeys.json

Jwt Ket 集允许连续提供多个公钥。您也可以提供 URL。

另外,请忘记 mp.jwt.verify.issuer:该属性需要一个表示单个颁发者的字符串。此属性不是强制性的,因此如果您确实想控制颁发者,则必须在请求过滤器中自行控制它。

如果您的公钥只有 PEM 文件,您可以使用 PEM 到 JWT 转换器将它们转换为 Jwt 密钥集,例如 这个(在线)。然后您只需提供 .json 文件即可。

Yes. But using a JSON Jwt Key Set:

mp.jwt.verify.publickey.location=my-pubkeys.json

The Jwt Ket Set allows to provide several public keys in row. You can also provide an URL instead.

Also, forget about mp.jwt.verify.issuer: the property expects a string representing a single issuer. This property is not mandatory, so if you really want to control the issuer you will have to control it by yourself in your request filter.

If you only have PEM files for your pubkeys, you can turn them into Jwt Key Set using PEM to JWT convertor like this one (online). Then you just have to serve the .json file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文