刷新oauth2令牌google api和HWIOAuthBundle

Dev*_*per 10 php google-api symfony google-api-php-client hwioauthbundle

我怎么刷新令牌?我使用带有此令牌的Google api - 它可以工作但无法找到如何刷新它,在这个例子中我们不保存过期时间.我需要

`access_type:     offline `
Run Code Online (Sandbox Code Playgroud)

然后

$client = new Google_Client();
        //$client->setClientId($GoogleClientId);
        $client->setApplicationName($GoogleAppName);
        $client->setClientId($this->user->getGoogleId());
        $client->setAccessType('offline');
Run Code Online (Sandbox Code Playgroud)

如果令牌有效,我可以工作但是什么时候过期我试试

$token = [
            'access_token' => $this->user->getGoogleAccessToken(),
            'expires_in'   => (new \DateTime())->modify('-1 year')->getTimestamp(),
        ];
Run Code Online (Sandbox Code Playgroud)

我把它放在任何日期,因为在这个例子中我们不保存过期时间

https://gist.github.com/danvbe/4476697

    $client->setAccessToken($token);

    if($client->isAccessTokenExpired()){

        $refreshedToken = $client->refreshToken($client->getAccessToken());
Run Code Online (Sandbox Code Playgroud)

我有错误

array:2 [?
  "error" => "invalid_request"
  "error_description" => "Could not determine client ID from request."
]
Run Code Online (Sandbox Code Playgroud)

有HwiAuthBundle方法来刷新令牌吗?为什么这不适用于Google_Client刷新?

del*_*8uk -2

很抱歉让您不高兴,朋友,但看起来该包没有实现任何刷新令牌功能。或者由你决定。

这是他们的 GitHub 中的未解决问题,请查看:https://github.com/hwi/HWIOAuthBundle/issues/457

这是该问题的评论:

此功能存在,但使用起来并不方便,因为您需要自己完成所有操作(处理存储有关令牌的更多详细信息、检测过期、调用 Google 获取新令牌以及替换旧令牌),只有此帮助现在,它的代码允许您向 Google 请求新的新鲜令牌:GenericOAuth2ResourceOwner::refreshToken(),它应该按预期工作,但我已经很长时间没有使用这个包了 =)

那里的人们正在等待要点(代码片段)来向他们展示如何做到这一点,但到目前为止还没有任何进展。