我如何刷新令牌?我使用Google与此令牌-它工作,但找不到如何刷新它,在本例中,我们没有节省过期的时间。我要求
`access_type: offline `然后
$client = new Google_Client();
//$client->setClientId($GoogleClientId);
$client->setApplicationName($GoogleAppName);
$client->setClientId($this->user->getGoogleId());
$client->setAccessType('offline');如果令牌是有效的,我可以工作,但当过期时,我尝试
$token = [
'access_token' => $this->user->getGoogleAccessToken(),
'expires_in' => (new \DateTime())->modify('-1 year')->getTimestamp(),
];我把这个日期放在任何日期,因为在这个例子中我们没有节省过期的时间
https://gist.github.com/danvbe/4476697
$client->setAccessToken($token);
if($client->isAccessTokenExpired()){
$refreshedToken = $client->refreshToken($client->getAccessToken());这里我有错误
array:2 [▼
"error" => "invalid_request"
"error_description" => "Could not determine client ID from request."
]有HwiAuthBundle方法来刷新令牌吗?为什么这不适用于Google_Client刷新?
发布于 2017-09-20 07:34:08
在oauth2.0中,要刷新过期的访问令牌,需要发送到端点:
您不能发送过期的accessToken来获得一个新的刷新的accessToken.
public function refreshAccessToken($refreshToken, array $extraParameters = array())
{
$parameters = array_merge(array(
'refresh_token' => $refreshToken,
'grant_type' => 'refresh_token',
'client_id' => $this->options['client_id'],
'client_secret' => $this->options['client_secret'],
), $extraParameters);
$response = $this->doGetTokenRequest($this->options['access_token_url'], $parameters);
$response = $this->getResponseContent($response);
$this->validateResponseContent($response);
return $response;
}函数refreshAccessToken($refreshToken,..。
而非$accessToken
我认为你需要在用你的凭证构造你的客户之后打电话给你
$client = new Google_Client();
$client->setAuthConfig('client_secrets.json');
$client->refreshToken($client->getRefreshToken());https://developers.google.com/api-client-library/php/auth/web-app#creatingcred
你确定你的$client->setClientId($this->user->getGoogleId());吗?getGoogleId()是什么?我认为您还需要创建一个oauth客户机id:https://developers.google.com/identity/sign-in/web/devconsole-project
oauth client_id中的client_id不是用户id,而是应用程序id。
发布于 2017-09-19 11:31:38
很抱歉打扰您,朋友,但是看起来那个包没有实现任何刷新令牌功能。或者由你自己决定。
下面是他们的GitHub中的公开问题,来看看:https://github.com/hwi/HWIOAuthBundle/issues/457
下面是这个问题的一个评论:
这个特性是存在的,但是它并不容易使用,因为您需要自己完成所有事情(处理存储令牌的更多细节、检测过期信息、调用Google获取新令牌和替换旧令牌),目前只能从这个包中获得帮助,它的代码允许您向Google请求新的令牌: GenericOAuth2ResourceOwner::refreshToken(),它应该按预期工作,但是我很长时间没有使用这个包了=)
那里的人们都在等待Gist (代码片段)来向他们展示如何做到这一点,但到目前为止还没有。
https://stackoverflow.com/questions/40523329
复制相似问题