使用Firebase令牌进行身份验证

时间:2018-07-14 10:23:03

标签: javascript firebase firebase-realtime-database firebase-security-rules

我已使用以下代码在Firebase数据库中对测试用户进行了身份验证:

  login(email, password) {
    this.firebaseAuth.auth.signInWithEmailAndPassword(email, password)
      .then(value => {
        console.log('Nice, it worked!', value);
        this.firebaseAuth.auth.currentUser.getIdToken(true)
          .then((idToken) => {
            // print out token
            console.log('Id token -> ', idToken);
          });
      })
      .catch(err => {
        console.log('Something went wrong:',err.message);
      });
  }

在此用户的此位置,我有课程列表:

enter image description here

此数据库上的规则如下:

// These rules grant access to a node matching the authenticated
// user's ID from the Firebase auth token
{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}

我正尝试在Postman中进行测试,以查看是否可以为此用户访问数据库并获取该位置的用户列表,但我还是返回not found或Google在屏幕上登录。

使用Firebase令牌时,是否可以将授权令牌作为标头发送?还是仅用于Google OAuth令牌?

根据此article,我应该可以执行以下操作来访问数据库并取回数据:

curl "https://<DATABASE_NAME>.firebaseio.com/users/ada/name.json?auth=<ID_TOKEN>"

在我看来,它应该像这样:

curl "https://<DATABASE_NAME>.firebaseio.com/<GUID>/courses?auth=<ID_TOKEN>"

我的邮递员请求标头看起来像这样:

授权 firebase-token

0 个答案:

没有答案
相关问题