We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello guys!
Maybe i ran into a bug or i misconfigured anything. Hope anyone can help me.
I'm using the GoogleResponseOwner to authenticate my users. I save the access_token, expires_in and the refresh_token in my MySQL database.
GoogleResponseOwner
The problem is that refresh_token is always null. According to their [docs] https://developers.google.com/accounts/docs/OAuth2WebServer?hl=de#handlingtheresponse) i have to set the access_type to offline (which i do) but the response_token isn't set in the response from google.
refresh_token
null
offline
response_token
I really need to refresh my access_token because i need to load some data from the google analytics api.
1. config.yml
hwi_oauth: firewall_name: main fosub: properties: google: googleId connect: account_connector: acme.security.provider.user resource_owners: google: type: google client_id: <my_id> client_secret: <my_secret> scope: "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/analytics.readonly" options: access_type: offline
2. UserProvider
class UserProvider implements OAuthAwareUserProviderInterface, UserProviderInterface { private $userManager; public function __construct(UserManager $userManager) { $this->userManager = $userManager; } public function connect($user, UserResponseInterface $response) { $username = $response->getUsername(); $previousUser = $this->userManager->findUserBy(array('googleId' => $username)); /** @var $user User */ /** @var $previousUser User */ $user->setGoogleId($username); $user->setGoogleToken($response->getAccessToken()); $user->setAvatarUrl($response->getProfilePicture()); $user->setGoogleRefreshToken($response->getRefreshToken()); $user->setGoogleTokenExpires($response->getExpiresIn()); if ($user === $previousUser) { return; } if (null !== $previousUser) { $previousUser->setGoogleId(null); $previousUser->setGoogleToken(null); $previousUser->setAvatarUrl(null); $previousUser->setGoogleRefreshToken(null); $previousUser->setGoogleTokenExpires(null); $this->userManager->updateUser($previousUser); } $this->userManager->updateUser($user); } public function loadUserByOAuthUserResponse(UserResponseInterface $response) { $username = $response->getUsername(); $user = $this->userManager->findUserBy(array('googleId' => $username)); if (!$user) { throw new AccountNotLinkedException(sprintf('No user with google username "%s" was found.', $username)); } /** @var $user User */ if (!$user->getGoogleToken()) { $user->setGoogleToken($response->getAccessToken()); $user->setGoogleRefreshToken($response->getRefreshToken()); $user->setGoogleTokenExpires($response->getExpiresIn()); $this->userManager->updateUser($user); } return $user; } public function loadUserByUsername($usernameOrEmail) { $user = $this->userManager->findUserByUsernameOrEmail($usernameOrEmail); if (!$user) { throw new UsernameNotFoundException(sprintf('No user with name or email "%s" was found.', $usernameOrEmail)); } return $user; } /** * {@inheritDoc} */ public function refreshUser(UserInterface $user) { return $this->userManager->refreshUser($user); } /** * {@inheritDoc} */ public function supportsClass($class) { return $this->userManager->supportsClass($class); } }
The text was updated successfully, but these errors were encountered:
https://developers.google.com/accounts/docs/OAuth2WebServer?hl=de#refresh A refresh token is only returned the very first time you request authorisation. you should be able to reset this by revoking access to your app in the users account.
alternatively you can use approval_prompt=force to get a new refresh token. search the docs for approval_prompt
approval_prompt=force
approval_prompt
Sorry, something went wrong.
@bendavies Thank you for your comment and the explanation.
No branches or pull requests
Hello guys!
Maybe i ran into a bug or i misconfigured anything. Hope anyone can help me.
I'm using the
GoogleResponseOwner
to authenticate my users. I save the access_token, expires_in and the refresh_token in my MySQL database.The problem is that
refresh_token
is alwaysnull
.According to their [docs] https://developers.google.com/accounts/docs/OAuth2WebServer?hl=de#handlingtheresponse) i have to set the access_type to
offline
(which i do) but theresponse_token
isn't set in the response from google.I really need to refresh my access_token because i need to load some
data from the google analytics api.
1. config.yml
2. UserProvider
The text was updated successfully, but these errors were encountered: