Ejemplo n.º 1
0
 /**
  * Get token by ID
  */
 public function getTokenById($id)
 {
     if ($id) {
         $record = Oauth_TokenRecord::model()->findById($id);
         if ($record) {
             $token = Oauth_TokenModel::populateModel($record);
             // will refresh token if needed
             try {
                 if ($this->_refreshToken($token)) {
                     // save refreshed token
                     $this->saveToken($token);
                 }
             } catch (\Exception $e) {
                 OauthPlugin::log("OAuth.Debug - Couldn't refresh token\r\n" . $e->getMessage() . '\\r\\n' . $e->getTraceAsString(), LogLevel::Error, true);
             }
             return $token;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Get token by ID
  */
 public function getTokenById($id)
 {
     if ($id) {
         $record = Oauth_TokenRecord::model()->findById($id);
         if ($record) {
             $token = Oauth_TokenModel::populateModel($record);
             // will refresh token if needed
             try {
                 if ($this->_refreshToken($token)) {
                     // save refreshed token
                     $this->saveToken($token);
                 }
             } catch (\Exception $e) {
                 // todo: log
                 // throw $e;
                 // return null;
             }
             return $token;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Get token by ID
  */
 public function getTokenByEncodedToken($encodedToken)
 {
     if ($encodedToken) {
         $conditions = 'encodedToken=:encodedToken';
         $params = array(':encodedToken' => $encodedToken);
         $record = Oauth_TokenRecord::model()->find($conditions, $params);
         if ($record) {
             $token = Oauth_TokenModel::populateModel($record);
             // will refresh token if needed
             try {
                 if ($this->refreshToken($token)) {
                     // save refreshed token
                     $this->saveToken($token);
                 }
             } catch (\Exception $e) {
                 // todo: log
                 // throw $e;
             }
             return $token;
         }
     }
 }
Ejemplo n.º 4
0
 public function getUserToken($handle, $userId = null)
 {
     Craft::log(__METHOD__, LogLevel::Info, true);
     $record = $this->_getTokenRecord($handle, null, $userId);
     if ($record) {
         return Oauth_TokenModel::populateModel($record);
     }
     return null;
 }