{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2-authclient/issues/76","labels_url":"https://api.github.com/repos/yiisoft/yii2-authclient/issues/76/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2-authclient/issues/76/comments","events_url":"https://api.github.com/repos/yiisoft/yii2-authclient/issues/76/events","html_url":"https://github.com/yiisoft/yii2-authclient/issues/76","id":123066671,"number":76,"title":"GoogleOAuth cannot get refresh_token with approval_prompt","user":{"login":"vercotux","id":2930526,"avatar_url":"https://avatars.githubusercontent.com/u/2930526?v=3","gravatar_id":"","url":"https://api.github.com/users/vercotux","html_url":"https://github.com/vercotux","followers_url":"https://api.github.com/users/vercotux/followers","following_url":"https://api.github.com/users/vercotux/following{/other_user}","gists_url":"https://api.github.com/users/vercotux/gists{/gist_id}","starred_url":"https://api.github.com/users/vercotux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vercotux/subscriptions","organizations_url":"https://api.github.com/users/vercotux/orgs","repos_url":"https://api.github.com/users/vercotux/repos","events_url":"https://api.github.com/users/vercotux/events{/privacy}","received_events_url":"https://api.github.com/users/vercotux/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-19T06:30:31Z","updated_at":"2015-12-28T03:21:17Z","closed_at":null,"body":"Google will only send a *refresh_token* on the very first authorization and then never again. On any subsequent authorization only an *id_token* is sent which cannot be used to acquire a new access token once the old one has expired. This is a show-stopper when attempting to acquire the refresh token from users who have already been authorized in case something went wrong and the refresh token was not permanently stored. There are only two ways around this:\r\n\r\n* Ask your users to revoke access to your app in their Google account and try again (unrealistic), or\r\n* Sending an extra parameter ```approval_prompt``` to ```force```. More info on the topic [here](http://stackoverflow.com/a/10857806).\r\n\r\nUsing the *approval_prompt* parameter is however currently unsupported by the GoogleOAuth client."},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2-authclient/issues/comments/167467408","html_url":"https://github.com/yiisoft/yii2-authclient/issues/76#issuecomment-167467408","issue_url":"https://api.github.com/repos/yiisoft/yii2-authclient/issues/76","id":167467408,"user":{"login":"vercotux","id":2930526,"avatar_url":"https://avatars.githubusercontent.com/u/2930526?v=3","gravatar_id":"","url":"https://api.github.com/users/vercotux","html_url":"https://github.com/vercotux","followers_url":"https://api.github.com/users/vercotux/followers","following_url":"https://api.github.com/users/vercotux/following{/other_user}","gists_url":"https://api.github.com/users/vercotux/gists{/gist_id}","starred_url":"https://api.github.com/users/vercotux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vercotux/subscriptions","organizations_url":"https://api.github.com/users/vercotux/orgs","repos_url":"https://api.github.com/users/vercotux/repos","events_url":"https://api.github.com/users/vercotux/events{/privacy}","received_events_url":"https://api.github.com/users/vercotux/received_events","type":"User","site_admin":false},"created_at":"2015-12-28T03:21:17Z","updated_at":"2015-12-28T03:21:17Z","body":"I ended up overriding *authOAuth2($client)* in AuthAction. Here is the code:\r\n\r\n```PHP\r\nprotected function authOAuth2($client, $tokenParams = [], $urlParams = [])\r\n{\r\n\tif (isset($_GET['error'])) {\r\n\t\tif ($_GET['error'] == 'access_denied') {\r\n\t\t\t// user denied error\r\n\t\t\treturn $this->redirectCancel();\r\n\t\t} else {\r\n\t\t\t// request error\r\n\t\t\tif (isset($_GET['error_description'])) {\r\n\t\t\t\t$errorMessage = $_GET['error_description'];\r\n\t\t\t} elseif (isset($_GET['error_message'])) {\r\n\t\t\t\t$errorMessage = $_GET['error_message'];\r\n\t\t\t} else {\r\n\t\t\t\t$errorMessage = http_build_query($_GET);\r\n\t\t\t}\r\n\t\t\tthrow new Exception('Auth error: ' . $errorMessage);\r\n\t\t}\r\n\t}\r\n\t// Get the access_token and save them to the session.\r\n\tif (isset($_GET['code'])) {\r\n\t\t$code = $_GET['code'];\r\n\t\t$token = $client->fetchAccessToken($code,$tokenParams);\r\n\t\tif (!empty($token)) {\r\n\t\t\treturn $this->authSuccess($client);\r\n\t\t} else {\r\n\t\t\treturn $this->redirectCancel();\r\n\t\t}\r\n\t} else {\r\n\t\t$url = $client->buildAuthUrl($urlParams);\r\n\t\treturn Yii::$app->getResponse()->redirect($url);\r\n\t}\r\n}\r\n```\r\n\r\nI wish there was a more elegant way to do this."}}