Example #1
0
 /**
  * Show Auth View
  * 
  * @return  void
  */
 public function authorizeTask()
 {
     //create request & response objects
     $request = OAuth2\Request::createFromGlobals();
     $response = new OAuth2\Response();
     // get the application model (by client ID)
     $model = new Models\Api\Application();
     $this->view->application = $model->loadByClientId($request->query('client_id'));
     // force query string redirect param
     if (!$request->query('redirect_uri')) {
         throw new Exception('No redirect URI', 400);
     }
     // validate the authorize request
     if (!$this->server->validateAuthorizeRequest($request, $response)) {
         throw new Exception($response->getParameter('error_description'), 400);
     }
     // make sure were logged in
     if (User::isGuest()) {
         // redirect to login
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($_SERVER['REQUEST_URI'])), Lang::txt('You must be logged in to authorize %s', $this->view->application->get('name')), 'warning');
     }
     // display authorize form
     $this->view->display();
 }
 /**
  * Remove any existing tokens for applications
  * 
  * @return void
  */
 public function removeTokensTask()
 {
     // [SECURITY] Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('id', array(0));
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Do we actually have any entries?
     if (count($ids) < 1) {
         // No entries found, so go back to the entries list with
         // a message scolding the user for not selecting anything. Tsk, tsk.
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_DEVELOPER_SELECT_APPLICATION_TO', $this->_task), 'error');
         return;
     }
     // loop through each application id
     foreach ($ids as $id) {
         // Load the entry and revoke tokens/codes
         $row = new Models\Api\Application(intval($id));
         $row->revokeAccessTokens();
         $row->revokeRefreshTokens();
         $row->revokeAuthorizationCodes();
     }
     // Set the redirect URL to the main entries listing.
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_DEVELOPER_REVOKE_TOKENS_SUCCESS'));
 }
Example #3
0
 /**
  * Get authorization code details by code
  * 
  * @param   string  $code  Authorization code
  * @return  array   Code details
  */
 public function getAuthorizationCode($code)
 {
     // auth model
     $authorizationCode = \Components\Developer\Models\Authorizationcode::oneByCode($code);
     // fetch by code
     if (!$authorizationCode->get('id')) {
         return false;
     }
     // get the application's client id
     $application = \Components\Developer\Models\Api\Application::oneOrFail($authorizationCode->get('application_id'));
     $authorizationCode->set('client_id', $application->get('client_id'));
     // format expires to unix timestamp for authorization code grant type
     $authorizationCode->set('expires', with(new Date($authorizationCode->get('expires')))->toUnix());
     // return code
     return $authorizationCode->toArray();
 }
 /**
  * Build Breadcrumb Trail
  * 
  * @return  void
  */
 protected function _buildPathway()
 {
     // create breadcrumbs
     if (Pathway::count() <= 0) {
         Pathway::append(Lang::txt(strtoupper($this->_option)), 'index.php?option=' . $this->_option);
     }
     // add "API"
     Pathway::append(Lang::txt('COM_DEVELOPER_API'), 'index.php?option=' . $this->_option . '&controller=api');
     // add "Applications"
     Pathway::append(Lang::txt('COM_DEVELOPER_API_APPLICATIONS'), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller);
     // do we have an application
     if ($appid = Request::getInt('id', 0)) {
         $application = new Models\Api\Application($appid);
         // add "Applications"
         Pathway::append($application->get('name'), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&id=' . $appid);
     }
     // add task
     if (isset($this->_task) && !in_array($this->_task, array('view', 'display', 'applications', 'granted'))) {
         // add "Applications"
         Pathway::append(Lang::txt('COM_DEVELOPER_API_APPLICATION_' . strtoupper($this->_task)), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&id=' . $appid . '&task=' . $this->_task);
     }
     // add active
     if ($active = Request::getCmd('active', null)) {
         // add "Applications"
         Pathway::append(Lang::txt(ucfirst($active)), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&id=' . $appid . '&task=' . $this->_task);
     }
 }