gpt4 book ai didi

java - Firebase:无法验证 Firebase ID token 的签名

转载 作者:行者123 更新时间:2023-12-04 08:10:43 65 4
gpt4 key购买 nike

当我尝试在 Spring Boot 后端应用程序中验证 Firebase jwt token 时,出现以下错误:

Failed to verify the signature of Firebase ID token. Seehttps://firebase.google.com/docs/auth/admin/verify-id-tokens fordetails on how to retrieve an ID token.


在客户端 (Flutter) 中,我按如下方式记录 jwt:
  GoogleSignInAccount googleSignInAccount = await _googleSignIn.signIn();
GoogleSignInAuthentication googleSignInAuthentication = await googleSignInAccount.authentication;

AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);

UserCredential authResult = await _auth.signInWithCredential(credential);
_user = authResult.user;

logger.i(await _user.getIdToken()); // Print jwt
我将通过 Authorization header 记录到我的后端的 jwt 作为不记名 token 发送。
使用 Spring 安全性(没关系),我只执行以下检查:
FirebaseToken decoded = FirebaseAuth.getInstance().verifyIdToken(token);
我的 firebase 应用程序初始化配置非常标准(设置了指向 config.json 的 env 变量):
@Primary
@Bean
public void firebaseInit() throws IOException {
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.getApplicationDefault())
.build();
if (FirebaseApp.getApps().isEmpty()) {
FirebaseApp.initializeApp(options);
}
}
调试后,下面的方法抛出类RSASignature(包sun.security.rsa):
@Override
protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
if (publicKey == null) {
throw new SignatureException("Missing public key");
}
try {
if (sigBytes.length != RSACore.getByteLength(publicKey)) {
throw new SignatureException("Signature length not correct: got " +
sigBytes.length + " but was expecting " +
RSACore.getByteLength(publicKey));
}
sigBytes 长度为 113,而它预计为 256。
也许我做错了什么...

最佳答案

我的天……我在 dart 中使用的记录器决定只对 jwt 字符串加盖,这样 jwt 就不完整了。
现在我收到一条消息“禁止”快乐。但是之前的错误已经解决了。
编辑“禁止”是一个小的 Spring Boot 问题(向权限添加角色)的结果。
它现在按预期工作。

关于java - Firebase:无法验证 Firebase ID token 的签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65980838/

65 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com