Exemple #1
0
 /**
  * Get Access token data
  * 
  * @param   string  $access_token  Access token
  * @return  array   Access token data
  */
 public function getAccessToken($access_token)
 {
     // create access token
     $token = \Components\Developer\Models\Accesstoken::oneByToken($access_token);
     // make sure we have a token
     if (!$token->get('id')) {
         return false;
     }
     // make sure its a published token
     if (!$token->isPublished()) {
         return false;
     }
     // get the application's client id
     $application = \Components\Developer\Models\Application::oneOrFail($token->get('application_id'));
     $token->set('client_id', $application->get('client_id'));
     // format expires to unix timestamp
     $token->set('expires', with(new Date($token->get('expires')))->toUnix());
     // return token
     return $token->toArray(true);
 }
 /**
  * Revoke application token
  * 
  * @return  void
  */
 public function revokeTask()
 {
     // CSRF check
     Request::checkToken('get');
     // get the app id
     $id = Request::getInt('id', 0);
     $token = Request::getInt('token', 0);
     // must be logged in
     if (User::isGuest()) {
         $return = Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=view&id=' . $id, false, true);
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($return)));
         return;
     }
     // get access tokens apps
     $accessToken = Accesstoken::oneOrFail($token);
     // delete the access token
     if ($accessToken->get('application_id') == $id) {
         $accessToken->destroy();
     }
     $return = Route::url('index.php?option=com_developer&controller=applications');
     if (Request::getvar('return') == 'tokens') {
         $return = Route::url('index.php?option=com_developer&controller=applications&id=' . $id . '&active=tokens');
     }
     // Redirect back to the main listing with a success message
     App::redirect($return, Lang::txt('COM_DEVELOPER_API_APPLICATION_AUTHORIZED_REVOKED'), 'passed');
 }