2017-08-06 73 views
0

我试图使用自定义身份验证将用户身份验证到Firebase。按照文档中的指导创建了jwt令牌。但发送令牌后,我得到这个响应Firebase自定义身份验证失败400

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" 
} 

控制台

代码: “认证/内部 - 错误”,邮件: “{” 错误 “:{” 错误“: {“domain”:“global”,“reason”:“i ... CLAIMS”}],“code”:400,“message”:“INVALID_CLAIMS”}}“

我的jwt令牌也是正确的格式。

PHP代码使用以产生令牌JWT

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"); 
    } 

回答

1

在“权利要求”在自定义令牌字段应包含代替JSON数组JSON对象。