Beispiel #1
0
 protected function entry()
 {
     if (!($this->lib = OAuth2Builder::getByKey($this->service->key))) {
         $this->error(Authorization::ERR_SERVER_ERROR);
         return false;
     }
     try {
         if (!($code = $this->lib->getCode($_GET))) {
             throw new Exception(Exception::OAUTH2_WRONG_CODE, array('uri' => $_SERVER['REQUEST_URI'], 'err' => $this->lib->getError()));
         }
         if (!$this->lib->requestToken($code) || !$this->lib->getToken()) {
             throw new Exception(Exception::OAUTH2_WRONG_TOKEN, array('uri' => $this->lib->getTokenUri($code), 'err' => $this->lib->getError(), 'response' => $this->lib->getResponseString()));
         }
         /*$this->data = array
           (
               'access_token'    => $this->lib->getToken(),
               'refresh_token'   => (($v = $this->lib->getRefreshToken()) === false)? null: $v,
               'expires_in'      => (($v = $this->lib->getExpiresIn()) === false)? null: $v,
               'server_response' => (($v = $this->lib->getResponseString()) === false)? null: $v
           );*/
         return true;
     } catch (Exception $ex) {
         switch ($this->lib->getError()) {
             case OAuth2Lib::ERR_ACCESS_DENIED:
             case OAuth2Lib::ERR_UNATHORIZED_CLIENT:
             case OAuth2Lib::ERR_INVALID_CLIENT:
                 $this->page1(self::ERR_ACCESS);
             default:
                 $this->page1(self::ERR_INTERNAL);
         }
         return false;
     }
 }
Beispiel #2
0
 public static function getSettings()
 {
     $kvdb = new KVDB('auth');
     if (!isset($kvdb->settings)) {
         $kvdb->settings = array('vk.uri' => OAuth2::getByKey('vk')->getCodeUri(), 'ok.uri' => OAuth2::getByKey('ok')->getCodeUri());
     }
     return $kvdb->settings;
 }