Ejemplo n.º 1
0
 /**
  * Generate an oauth_verifier for a consumer, if the consumer doesn't already have one.
  *
  * @param int $consumerId - The id of the consumer associated with the verifier to be generated.
  * @return $this
  */
 public function createVerifierToken($consumerId)
 {
     $tokenData = $this->getResource()->selectTokenByType($consumerId, self::TYPE_VERIFIER);
     $this->setData($tokenData ? $tokenData : array());
     if (!$this->getId()) {
         $this->setData(array('consumer_id' => $consumerId, 'type' => self::TYPE_VERIFIER, 'token' => $this->_oauthHelper->generateToken(), 'secret' => $this->_oauthHelper->generateTokenSecret(), 'verifier' => $this->_oauthHelper->generateVerifier(), 'callback_url' => OauthHelper::CALLBACK_ESTABLISHED, 'user_type' => UserContextInterface::USER_TYPE_INTEGRATION));
         $this->validate();
         $this->save();
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Authorize token
  *
  * @param int $userId Authorization user identifier
  * @param string $userType Authorization user type
  * @return $this
  * @throws OauthException
  */
 public function authorize($userId, $userType)
 {
     if (!$this->getId() || !$this->getConsumerId()) {
         throw new OauthException('Token is not ready to be authorized');
     }
     if ($this->getAuthorized()) {
         throw new OauthException('Token is already authorized');
     }
     if (self::USER_TYPE_ADMIN == $userType) {
         $this->setAdminId($userId);
     } elseif (self::USER_TYPE_CUSTOMER == $userType) {
         $this->setCustomerId($userId);
     } else {
         throw new OauthException('User type is unknown');
     }
     $this->setVerifier($this->_oauthHelper->generateVerifier());
     $this->setAuthorized(1);
     $this->save();
     $this->getResource()->cleanOldAuthorizedTokensExcept($this);
     return $this;
 }
Ejemplo n.º 3
0
 public function testGenerateVerifier()
 {
     $token = $this->_oauthHelper->generateVerifier();
     $this->assertTrue(is_string($token) && strlen($token) === Oauth::LENGTH_TOKEN_VERIFIER);
 }