Completed
Push — master ( 88b001...24ab37 )
by Derek Stephen
10:51
created

OAuthController::pingAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 3
cp 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Controller;
4
5
use Bone\Mvc\Controller;
6
use Del\Common\ContainerService;
7
use League\OAuth2\Server\AuthorizationServer;
8
use Psr\Http\Message\ResponseInterface;
9
use Zend\Diactoros\Response\SapiEmitter;
10
11
class OAuthController extends Controller
12
{
13
    /** @var AuthorizationServer $oauth2Server */
14
    protected $oauth2Server;
15
16
    public function init()
17
    {
18
19
        $container = ContainerService::getInstance()->getContainer();
20
        $clientRepository = $container['repository.Client'];
21
        $accessTokenRepository = $container['repository.AccessToken'];
22
        $scopeRepository = $container['repository.Scope'];
23
24
        // Setup the authorization server
25
        $server = new AuthorizationServer($clientRepository, $accessTokenRepository, $scopeRepository,
26
            'file://'.APPLICATION_PATH.'/data/keys/private.key',    // path to private key
27
            'file://'.APPLICATION_PATH.'/data/keys/public.key'      // path to public key
28
        );
29
        $server->setEncryptionKey('1De1boyXJzdk4TYmHkR3st6dJmHuEaneHB');
30
31
        $this->oauth2Server = $server;
32
    }
33
34
    /**
35
     * @param ResponseInterface $response
36
     */
37
    protected function sendResponse(ResponseInterface $response)
38
    {
39
        $emitter = new SapiEmitter();
40
        $emitter->emit($response);
41
        exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method sendResponse() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
42
    }
43
}
44