Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firebase身份验证令牌不';不包括额外的索赔_Javascript_Node.js_Firebase_Firebase Authentication_Firebase Security - Fatal编程技术网

Javascript Firebase身份验证令牌不';不包括额外的索赔

Javascript Firebase身份验证令牌不';不包括额外的索赔,javascript,node.js,firebase,firebase-authentication,firebase-security,Javascript,Node.js,Firebase,Firebase Authentication,Firebase Security,我正在尝试设置以下Firebase规则 { "rules": { "notification": { "$notif_id": { ".write": "auth.token.notif_id == $notif_id" } } } } 其中auth.token.notif\u id==$notif\u id给出了一个权限被拒绝的响应,我不明白为什么。(假设$notif\u id分支定义为abcd) 我在Node.js服务器上定义

我正在尝试设置以下Firebase规则

{
  "rules": {
    "notification": {
      "$notif_id": {
        ".write": "auth.token.notif_id == $notif_id"
      }
    }
  }
}
其中
auth.token.notif\u id==$notif\u id
给出了一个权限被拒绝的响应,我不明白为什么。(假设
$notif\u id
分支定义为
abcd

我在Node.js服务器上定义Firebase令牌,如下所示:

var params = {notif_id:'abcd'};
var firebase_token = Fb.auth().createCustomToken("uid", params);
然后,在HTML web浏览器代码中,我有以下内容:

var db = firebase.database();
function initApp() {
  firebase.auth().onAuthStateChanged(function(user) {
    if (user) {
      //do nothing
    }
  });
}

$('document').ready(function(){
  initApp();
  firebase.auth().signInWithCustomToken('<%=firebase_token%>').catch(function(error) {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    console.error('ERROR: '+errorCode);
    console.error(errorMessage);
  });
});
var db=firebase.database();
函数initApp(){
firebase.auth().onAuthStateChanged(函数(用户){
如果(用户){
//无所事事
}
});
}
$('document').ready(函数(){
initApp();
firebase.auth().signInWithCustomToken(“”).catch(函数(错误){
//在这里处理错误。
var errorCode=error.code;
var errorMessage=error.message;
console.error('error:'+errorCode);
控制台错误(错误消息);
});
});

您是否尝试记录访问令牌(您可以从onAuthStateChanged中的
用户
处获取)并对其进行解码以查看您的额外索赔?在哪里启动读取操作?“什么都不做”的评论将是一个很好的开始。嗯,你的代码看起来是正确的。按照说明获取已登录用户的ID令牌,然后将其插入。您应该在负载的顶层看到您的自定义声明。如果是这样,那么您的安全规则可能就是错误的。可能您实际上正在写入另一个节点或
$notif\u id
并非您所认为的那样。您解决了问题吗?您是否尝试过记录访问令牌(您可以从onAuthStateChanged中的
用户
处获取它)并对其进行解码以查看您的额外声明?在哪里启动读取操作?“什么都不做”的评论将是一个很好的开始。嗯,你的代码看起来是正确的。按照说明获取已登录用户的ID令牌,然后将其插入。您应该在负载的顶层看到您的自定义声明。如果是这样,那么您的安全规则可能就是错误的。可能您实际上正在向另一个节点写入数据,或者
$notif\u id
并非您所想象的那样。您解决了问题吗?