verifyIdToken 一次有效,另一次失败
verifyIdToken works one time and fails another time
我正在尝试在我的网站上实现 google 登录。
我已经完成了这里的步骤 Authenticate with Google.
此函数在我登录 google 后执行:
function onSignIn(googleUser) {
var googleResponse = googleUser.getAuthResponse();
google_login(googleResponse, true);
};
Google_login函数:
function google_login(res) {
var httpObject = getXMLHTTPObject();
var ajax_url = siteURL + 'google_login';
var params = 'token='+encodeURIComponent(res.id_token);
httpObject.open('POST', ajax_url, true);
httpObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpObject.onreadystatechange = function() {
if (httpObject.readyState == 4) {
if(httpObject.responseText == 'true') {
window.location = httpObject.responseURL;
}
else {
if(httpObject.responseText == '') {
window.location = siteURL + 'login_again';
}
else {
window.location = siteURL + 'google_login_error';
}
}
}
};
httpObject.send(params);
}
在我的模型中,我使用了这段代码:
private $google_client;
function Google_model() {
parent::__construct();
$this->google_client = new Google_Client(['client_id' => 'my_client_id','client_secret' =>'my_client_secret']);
}
function check_google_user($access_token) {
$payload = $this->google_client->verifyIdToken($access_token);
if ($payload) {
return $payload;
}
return false;
}
在我的控制器中,我正在调用 check_google_user 函数。
这里出现了一种奇怪的行为。有时,当我尝试登录时,我会收到有效负载,有时则不会(PS:我正在尝试在同一天使用同一用户登录)。我做错了什么吗?
编辑:
我收到此错误:捕获异常:无法处理 2017-01-25T16:20:24+0200 之前的令牌
通过在 firebase JWT.php 文件中注释这些行解决了这个问题:
throw new BeforeValidException(
'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->iat)
);
我正在尝试在我的网站上实现 google 登录。 我已经完成了这里的步骤 Authenticate with Google. 此函数在我登录 google 后执行:
function onSignIn(googleUser) {
var googleResponse = googleUser.getAuthResponse();
google_login(googleResponse, true);
};
Google_login函数:
function google_login(res) {
var httpObject = getXMLHTTPObject();
var ajax_url = siteURL + 'google_login';
var params = 'token='+encodeURIComponent(res.id_token);
httpObject.open('POST', ajax_url, true);
httpObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpObject.onreadystatechange = function() {
if (httpObject.readyState == 4) {
if(httpObject.responseText == 'true') {
window.location = httpObject.responseURL;
}
else {
if(httpObject.responseText == '') {
window.location = siteURL + 'login_again';
}
else {
window.location = siteURL + 'google_login_error';
}
}
}
};
httpObject.send(params);
}
在我的模型中,我使用了这段代码:
private $google_client;
function Google_model() {
parent::__construct();
$this->google_client = new Google_Client(['client_id' => 'my_client_id','client_secret' =>'my_client_secret']);
}
function check_google_user($access_token) {
$payload = $this->google_client->verifyIdToken($access_token);
if ($payload) {
return $payload;
}
return false;
}
在我的控制器中,我正在调用 check_google_user 函数。 这里出现了一种奇怪的行为。有时,当我尝试登录时,我会收到有效负载,有时则不会(PS:我正在尝试在同一天使用同一用户登录)。我做错了什么吗?
编辑:
我收到此错误:捕获异常:无法处理 2017-01-25T16:20:24+0200 之前的令牌
通过在 firebase JWT.php 文件中注释这些行解决了这个问题:
throw new BeforeValidException(
'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->iat)
);