Skip to content
Snippets Groups Projects
Select Git revision
  • d063b9291a2dbc42d40227af18df3b36837a3186
  • master default protected
  • improvements-2023
  • studip-5.3
  • 4.5
  • v3.1.0
  • v3.0
  • v2.1.1
  • v2.1.0
  • v2.0.1
10 results

file.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    oauth2_controller.php 1.36 KiB
    <?php
    
    use League\OAuth2\Server\AuthorizationServer;
    use League\OAuth2\Server\Exception\OAuthServerException;
    use Studip\OAuth2\NegotiatesWithPsr7;
    
    abstract class OAuth2Controller extends StudipController
    {
        use NegotiatesWithPsr7;
    
        /**
         * @return void
         */
        public function before_filter(&$action, &$args)
        {
            parent::before_filter($action, $args);
    
            page_open([
                'sess' => 'Seminar_Session',
                'auth' => 'Seminar_Default_Auth',
                'perm' => 'Seminar_Perm',
                'user' => 'Seminar_User',
            ]);
    
            $this->set_layout(null);
    
            $this->container = new Studip\OAuth2\Container();
            $this->server = $this->getAuthorizationServer();
        }
    
        /**
         * Exception handler called when the performance of an action raises an
         * exception.
         *
         * @param Exception $exception the thrown exception
         */
        public function rescue($exception)
        {
            if ($exception instanceof OAuthServerException) {
                $psrResponse = $exception->generateHttpResponse($this->getPsrResponse());
    
                return $this->convertPsrResponse($psrResponse);
            }
    
            return new Trails_Response($exception->getMessage(), [], 500);
        }
    
        protected function getAuthorizationServer(): AuthorizationServer
        {
            return $this->container->get(AuthorizationServer::class);
        }
    }