【发布时间】:2018-10-16 07:18:04
【问题描述】:
我正在尝试将 Auth0 JWT 令牌与 Firebase 一起使用,但运气不佳。
在 Firebase 中使用令牌时:
const token = localStorage.getItem('id_token'); //from auth0
firebase.auth().signInWithCustomToken(token).catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
console.log(error);
console.log(token);
});
我得到的是:
“The custom token format is incorrect. Please check the documentation.”
据我在 Firebase 的文档中看到的 Auth0 和 Firebase 令牌是不同的: https://firebase.google.com/docs/auth/admin/create-custom-tokens
显然,Firebase 需要一个 uid,而 Auth0 生成的 uid 中不存在该 uid 等效项在 sub 中。
我尝试创建一个规则来修改 Auth0 的令牌以包含一个名为 uid 的子副本,以查看这是否可以解决,但它不起作用,令牌正文中没有添加任何内容。
function (user, context, callback) {
context.idToken.uid = user.user_id;
callback(null, user, context);
}
有什么想法/建议吗?
PS:
1.我检查了 jwt.io 中的令牌及其有效。 2.我尝试将过期时间减少到不到 5 分钟,因为我看到一些人认为这是一个可能的解决方案,但事实并非如此。
【问题讨论】:
标签: javascript reactjs firebase firebase-authentication auth0