Quarkus 和 Firebase 身份验证

Quarkus and Firebase Authentication

我正在使用 Quarkus (1.3.2.Final) 开发一个新的 REST 服务,我正在尝试将 Firebase 身份验证与 Smallrye-Jwt 集成,但它失败了。

我的第一次尝试是将 publickey.location 指向 Google 的 URL 但它失败了,因为有两个密钥和正确的 public 检查签名的密钥取决于关于 jwt "kid" header 值:

mp.jwt.verify.publickey.location=https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com
mp.jwt.verify.issuer=https://securetoken.google.com/<projectId>
quarkus.smallrye-jwt.auth-mechanism=MP-JWT
quarkus.smallrye-jwt.enabled=true

我的第二次尝试是创建一个服务(类似于 "PublicKeyResolver")来请求 google 的 url 并根据 [=22] 提取正确的 public 密钥=] 声明价值:

mp.jwt.verify.publickey.location=http://localhost:8080/api/certs/publicKey

该策略失败,因为 "Authorization" http header 未包含在对 public 密钥的请求中。

有没有办法集成 Quarkus 和 Firebase 身份验证?

有一种 Quarkus-Firebase 集成的方法。根据 Quarkus 文档 mp.jwt.verify.publickey.location 是 Public 键的位置。此外,还定义了支持的 public 键格式 (https://quarkus.io/guides/security-jwt#supported-public-key-formats):

Public Keys may be formatted in any of the following formats, specified in order of precedence:

  • Public Key Cryptography Standards #8 (PKCS#8) PEM
  • JSON Web Key (JWK)
  • JSON Web Key Set (JWKS)
  • JSON Web Key (JWK) Base64 URL encoded
  • JSON Web Key Set (JWKS) Base64 URL encoded

因此,您的目标应该是指定 URL,其中包含 Public 格式为 JWKS 的密钥(因为 Smallrye-Jwt 无法接受 PKCS#8 PEM 集)。您尝试使用的 "Google URL" 不是 rfc7517 兼容的 JWK 集。

为了让它工作,您应该使用符合 rfc7517 的 Google JWKS URL:

mp.jwt.verify.publickey.location=https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com