Php Firebase自定义令牌无效
我在Firebase上使用自定义令牌身份验证。正如文档所说,我试图生成令牌。但是,当我尝试使用(Php Firebase自定义令牌无效,php,firebase,token,firebase-authentication,Php,Firebase,Token,Firebase Authentication,我在Firebase上使用自定义令牌身份验证。正如文档所说,我试图生成令牌。但是,当我尝试使用(loginWithCustomToken(token))方法登录客户端时,它会在下面给出一个错误 { "error": { "errors": [ { "domain": "global", "reason": "invalid", "message": "INVALID_CUSTOM_TOKEN" } ], "code": 400, "messa
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时间戳。