Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function get($code)
 {
     $token = new AuthCodeEntity($this->server);
     $token->setId('I0kXkdIMjrz0kk6HWifR9SOVb4N5VfaNTimL9XVU');
     $token->setRedirectUri('http://www.baidu.com');
     $token->setExpireTime(time());
     return $token;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  *
  * @param string $code Code
  * @return \League\OAuth2\Server\Entity\AuthCodeEntity|void
  */
 public function get($code)
 {
     $this->loadModel('OAuthServer.AuthCodes');
     $result = $this->AuthCodes->find()->where(['code' => $code, 'expires >=' => time()])->first();
     if ($result) {
         $token = new AuthCodeEntity($this->server);
         $token->setId($result->code);
         $token->setRedirectUri($result->redirect_uri);
         $token->setExpireTime($result->expires);
         return $token;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function get($code)
 {
     $result = $this->getConnection()->table('oauth_auth_codes')->where('auth_code', $code)->where('expire_time', '>=', time())->first();
     if (!is_null($result)) {
         $token = new AuthCodeEntity($this->server);
         $token->setId($result->auth_code);
         $token->setRedirectUri($result->client_redirect_uri);
         $token->setExpireTime($result->expire_time);
         return $token;
     }
     return;
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function get($code)
 {
     $result = Capsule::table('oauth_auth_codes')->where('auth_code', $code)->where('expire_time', '>=', time())->get();
     if (count($result) === 1) {
         $token = new AuthCodeEntity($this->server);
         $token->setId($result[0]['auth_code']);
         $token->setRedirectUri($result[0]['client_redirect_uri']);
         $token->setExpireTime($result[0]['expire_time']);
         return $token;
     }
     return;
 }
 /**
  * Get the auth code
  * @param  string $code
  * @return \League\OAuth2\Server\Entity\AuthCodeEntity
  */
 public function get($code)
 {
     $result = $this->db->fetchAll("SELECT * \n\t\t\tFROM oauth_auth_codes \n\t\t\tWHERE auth_code = :acode AND expire_time >= :etime", Db::FETCH_ASSOC, array("acode" => $code, "etime" => time()));
     if (count($result) === 1) {
         $token = new AuthCodeEntity($this->server);
         $token->setId($result[0]['auth_code']);
         $token->setRedirectUri($result[0]['client_redirect_uri']);
         $token->setExpireTime($result[0]['expire_time']);
         return $token;
     }
     return null;
 }
 /**
  * {@inheritdoc}
  */
 public function get($code)
 {
     $where['auth_code'] = array('eq', $code);
     $where['expire_time'] = array('egt', time());
     $result = M('oauth_auth_codes')->where($where)->select();
     if (count($result) === 1) {
         $token = new AuthCodeEntity($this->server);
         $token->setId($result[0]['auth_code']);
         $token->setRedirectUri($result[0]['client_redirect_uri']);
         $token->setExpireTime($result[0]['expire_time']);
         return $token;
     }
     return;
 }
Esempio n. 7
0
 /**
  * Parse a new authorize request
  *
  * @param string $type       The session owner's type
  * @param string $typeId     The session owner's ID
  * @param array  $authParams The authorize request $_GET parameters
  *
  * @return string An authorisation code
  */
 public function newAuthorizeRequest($type, $typeId, $authParams = [])
 {
     // Create a new session
     $session = new SessionEntity($this->server);
     $session->setOwner($type, $typeId);
     $session->associateClient($authParams['client']);
     // Create a new auth code
     $authCode = new AuthCodeEntity($this->server);
     $authCode->setId(SecureKey::generate());
     $authCode->setRedirectUri($authParams['redirect_uri']);
     $authCode->setExpireTime(time() + $this->authTokenTTL);
     foreach ($authParams['scopes'] as $scope) {
         $authCode->associateScope($scope);
         $session->associateScope($scope);
     }
     $session->save();
     $authCode->setSession($session);
     $authCode->save();
     return $authCode->generateRedirectUri($authParams['state']);
 }
 public function testDeleteAuthCode()
 {
     $redis = $this->prophesize("Corley\\OAuth2\\Server\\Storage\\Redis\\RedisMock");
     $redis->del("auth_code:auth_code_id")->shouldBeCalledTimes(1);
     $server = $this->prophesize("League\\OAuth2\\Server\\AbstractServer");
     $authCodeStorage = new AuthCodeStorage($redis->reveal());
     $authCodeStorage->setServer($server->reveal());
     $token = new AuthCodeEntity($server->reveal());
     $token->setId("auth_code_id");
     $token->setRedirectUri("http://localhost:8080/");
     $token->setExpireTime(11111);
     $authCodeStorage->delete($token);
 }