【问题标题】:Firebase custom authentication fails 400Firebase 自定义身份验证失败 400
【发布时间】:2017-08-06 18:27:03
【问题描述】:

我正在尝试使用自定义身份验证来向 Firebase 验证用户。按照文档中的指导创建 jwt 令牌。但是在发送令牌后我得到了这个响应

firebase.auth().signInWithCustomToken(response.body).catch(function (error) {
              // Handle Errors here.
              console.log(error)
            })

"error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "INVALID_CLAIMS"
   }
  ],
  "code": 400,
  "message": "INVALID_CLAIMS"
 }

控制台

代码:“身份验证/内部错误”,消息: "{"error":{"errors":[{"domain":"global","re​​ason":"i...CLAIMS"}],"code":400,"message":"INVALID_CLAIMS"}}"

我的 jwt 令牌格式也正确。

用于生成jwt令牌的php代码

public function authFirebase() {
        $now_seconds = time();
        $payload = [
          "iss" => $this->service_account_email,
          "sub" => $this->service_account_email,
          "aud" => "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
          "iat" => $now_seconds,
          "exp" => $now_seconds+(60*60),  // Maximum expiration time is one hour
          "uid" => \Auth::user()->id,
          "claims" => array()
        ];
        return JWT::encode($payload, $this->private_key, "RS256");
    }

【问题讨论】:

    标签: php firebase firebase-authentication


    【解决方案1】:

    自定义令牌中的“声明”字段应包含 JSON 对象,而不是 JSON 数组。

    【讨论】:

      猜你喜欢
      • 2022-08-10
      • 2020-04-01
      • 2022-12-10
      • 2020-10-29
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多