blob: 5bf2f9aa843d47a0749a75e6b412237deffbcf21 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<?php
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Exception\OAuthServerException;
use Studip\OAuth2\NegotiatesWithPsr7;
abstract class OAuth2Controller extends StudipController
{
use NegotiatesWithPsr7;
protected $with_session = true;
/**
* @return void
*/
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
$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);
}
}
|