【问题标题】:Firebase Invalid Custom TokenFirebase 自定义令牌无效
【发布时间】:2017-04-16 18:24:57
【问题描述】:

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

【问题讨论】:

  • 您的服务器可能有UTC 以外的时区。请为您的有效负载提供 UTC 时间戳。

标签: php firebase token firebase-authentication


【解决方案1】:

我解决了这个更新我的电脑的时间。 日期和时间错误,当我更新它时,错误已解决

【讨论】:

    猜你喜欢
    • 2017-12-19
    • 2016-09-27
    • 1970-01-01
    • 2012-12-26
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    相关资源
    最近更新 更多