【发布时间】: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