Firebase无效的自定义标记

时间:2016-12-01 23:10:51

标签: php firebase token firebase-authentication

我在Firebase上使用自定义令牌身份验证。我试图生成令牌,因为文档说。但是当我尝试使用(loginWithCustomToken(token))方法在客户端登录时,它会给出一个错误

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

我使用此代码块生成令牌,如Firebase文档中所述

$service_account_email = "USED_FROM_JSON_FILE"; //
$private_key = "USED_FROM_JSON_FILE";

function create_custom_token($uid, $is_premium_account) {
  global $service_account_email, $private_key;

  $now_seconds = time();
  $payload = array(
    "iss" => $service_account_email,
    "sub" => $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" => $uid,
    "claims" => array(
      "premium_account" => $is_premium_account
    )
  );
  return JWT::encode($payload, $private_key, "RS256");
}

1 个答案:

答案 0 :(得分:0)

我解决了更新PC时间的问题。 日期和时间有误,当我更新它时,错误已解决