Esempio n. 1
0
 /**
  * Delete a client. Deletes all associated tokens and codes.
  *
  * @param Oauth_ClientDao $clientDao
  * @throws Zend_Exception
  */
 public function delete($clientDao)
 {
     $tokens = $clientDao->getTokens();
     /** @var Oauth_TokenModel $tokenModel */
     $tokenModel = MidasLoader::loadModel('Token', 'oauth');
     foreach ($tokens as $token) {
         $tokenModel->delete($token);
     }
     $tokens = null;
     $codes = $clientDao->getCodes();
     /** @var Oauth_CodeModel $codeModel */
     $codeModel = MidasLoader::loadModel('Code', 'oauth');
     foreach ($codes as $code) {
         $codeModel->delete($code);
     }
     $codes = null;
     parent::delete($clientDao);
 }
Esempio n. 2
0
 /**
  * Create and return a new oauth authorization code for the given client and user. Expires after 10 minutes
  * in accordance with the recommendation in the IETF draft v31.
  *
  * @param UserDao $userDao resource owner (end user to authenticate via the client)
  * @param Oauth_ClientDao $clientDao client that will be receiving the code
  * @param array $scopes array of permission scopes (see api module constants)
  * @return Oauth_CodeDao
  * @throws Zend_Exception
  */
 public function create($userDao, $clientDao, $scopes)
 {
     if (!$userDao instanceof UserDao) {
         throw new Zend_Exception('Invalid userDao');
     }
     if (!$clientDao instanceof Oauth_ClientDao) {
         throw new Zend_Exception('Invalid userDao');
     }
     if (!is_array($scopes)) {
         throw new Zend_Exception('Scopes must be an array');
     }
     /** @var RandomComponent $randomComponent */
     $randomComponent = MidasLoader::loadComponent('Random');
     /** @var Oauth_CodeDao $codeDao */
     $codeDao = MidasLoader::newDao('CodeDao', $this->moduleName);
     $codeDao->setCode($randomComponent->generateString(32));
     $codeDao->setScopes(JsonComponent::encode($scopes));
     $codeDao->setUserId($userDao->getKey());
     $codeDao->setClientId($clientDao->getKey());
     $codeDao->setCreationDate(date('Y-m-d H:i:s'));
     $codeDao->setExpirationDate(date('Y-m-d H:i:s', strtotime('+10 minutes')));
     $this->save($codeDao);
     return $codeDao;
 }
Esempio n. 3
0
 /**
  * Expire all existing tokens for the given user and client.
  *
  * @param UserDao $userDao user DAO
  * @param Oauth_ClientDao $clientDao client DAO
  */
 public function expireTokens($userDao, $clientDao)
 {
     $data = array('expiration_date' => date('Y-m-d H:i:s'));
     $this->database->getDB()->update('oauth_token', $data, 'user_id = ' . $userDao->getKey() . ' AND client_id = ' . $clientDao->getKey());
 }