signInWithCustomToken()使用Firebase自己的令牌

问题描述 投票:8回答:1

我想通过共享JWT令牌来验证多个网站上的用户。令牌最初是由firebase生成的,所以我认为它是一个好的有效令牌(在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 live网站......但结果相同。我正在使用Firebase 3.3。

任何想法,什么可能是错的?我在旧版Firebase中使用此功能。

firebase-authentication
1个回答
1
投票

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

我假设您正在使用node.js生成自定义令牌。在您的节点脚本中尝试此操作:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.