gpt4 book ai didi

firebase-authentication - signInWithCustomToken() 与 Firebase 自己的 token

转载 作者:行者123 更新时间:2023-12-04 08:47:55 36 4
gpt4 key购买 nike

我想通过共享 JWT token 对多个网站上的用户进行身份验证。该 token 最初是由 firebase 生成的,所以我认为它是一个很好且有效的 token (在 jwt.io 上测试过,似乎没问题)。我收到了 user.getToken() .

当我打电话时 signInWithCustomToken(token)我总是收到错误 auth/invalid-custom-token留言 "The custom token format is incorrect. Please check the documentation." .

奇怪的是,它向 https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken... 发出 HTTP POST 请求。它返回 HTTP 400。我在 localhost 和 https 实时网站上都尝试过......但结果相同。我正在使用 Firebase 3.3。

任何想法,可能有什么问题?我在旧的 Firebase 中使用了这个功能。

最佳答案

你没有提供任何代码片段,所以我会在这里推测。

我假设您正在使用 node.js 生成自定义 token 。
在你的节点脚本中试试这个:

var firebase = require("firebase");
var adminConfig = {
serviceAccount: "serviceAccountCredentials.json"
};
var adminApp = firebase.initializeApp(adminConfig, 'admin');
var token = adminApp.auth().createCustomToken('12345678', {
customField: 'customValue'
});

然后在客户端尝试 signInWithCustomToken(token)
确保客户端使用的 api key 属于生成服务帐户的同一项目。

关于firebase-authentication - signInWithCustomToken() 与 Firebase 自己的 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39110455/

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