コード例 #1
0
 /**
  * Get Account
  */
 public function getAccount($token)
 {
     $provider = $this->getProvider();
     $realToken = OauthHelper::getRealToken($token);
     $response = $provider->getUserDetails($realToken);
     return $response->getIterator();
 }
コード例 #2
0
ファイル: OauthService.php プロジェクト: dukt/craft-oauth
 /**
  * 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;
 }
コード例 #3
0
ファイル: Provider.php プロジェクト: todamoon/lHenry
 /**
  * Get Account
  */
 public function getAccount()
 {
     $token = OauthHelper::getRealToken($this->token);
     return $this->getProvider()->getUserDetails($token);
 }
コード例 #4
0
ファイル: BaseProvider.php プロジェクト: dukt/craft-oauth
 /**
  * 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;
     }
 }