/** * Get Account */ public function getAccount($token) { $provider = $this->getProvider(); $realToken = OauthHelper::getRealToken($token); $response = $provider->getUserDetails($realToken); return $response->getIterator(); }
/** * Refresh token */ private function _refreshToken(Oauth_TokenModel $model) { $time = time(); // force refresh for testing // $time = time() + 3595; // google ttl // $time = time() + 50400005089; // facebook ttl $provider = craft()->oauth->getProvider($model->providerHandle); // Refreshing the token only applies to OAuth 2.0 providers if ($provider && $provider->getOauthVersion() == 2) { // Has token expired ? if ($time > $model->endOfLife) { $realToken = OauthHelper::getRealToken($model); $infos = $provider->getInfos(); $refreshToken = $model->refreshToken; $grant = new \League\OAuth2\Client\Grant\RefreshToken(); $newToken = $provider->getProvider()->getAccessToken($grant, ['refresh_token' => $refreshToken]); if ($newToken) { $model->accessToken = $newToken->getToken(); $model->endOfLife = $newToken->getExpires(); $newRefreshToken = $newToken->getRefreshToken(); if (!empty($newRefreshToken)) { $model->refreshToken = $newToken->getRefreshToken(); } return true; } } } return false; }
/** * Get Account */ public function getAccount() { $token = OauthHelper::getRealToken($this->token); return $this->getProvider()->getUserDetails($token); }
/** * Returns the remote resource owner. * * @param $token * * @return mixed */ public function getRemoteResourceOwner($token) { $provider = $this->getProvider(); $realToken = OauthHelper::getRealToken($token); switch ($this->getOauthVersion()) { case 1: return $provider->getUserDetails($realToken); break; case 2: return $provider->getResourceOwner($realToken); break; } }