Completed
Push — master ( 2a258c...683c35 )
by Alexandre
02:27
created

OAuthServer::createResourceServer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Alexandre
5
 * Date: 21/04/2018
6
 * Time: 18:45
7
 */
8
9
namespace OAuth2;
10
11
12
use OAuth2\Roles\AuthorizationServer\AuthorizationServer;
13
use OAuth2\Roles\AuthorizationServer\EndUserInterface;
14
use OAuth2\Roles\ResourceServer\BearerAuthenticationMethods\FormEncodedBodyParameter;
15
use OAuth2\Roles\ResourceServer\BearerAuthenticationMethods\URIQueryParameter;
16
use OAuth2\Roles\ResourceServer\ResourceServer;
17
use OAuth2\ScopePolicy\ScopePolicyManager;
18
use OAuth2\Storages\AccessTokenStorageInterface;
19
use OAuth2\Storages\AuthorizationCodeStorageInterface;
20
use OAuth2\Storages\ClientStorageInterface;
21
use OAuth2\Storages\RefreshTokenStorageInterface;
22
use OAuth2\Storages\ResourceOwnerStorageInterface;
23
use OAuth2\Storages\StorageManager;
24
25
class OAuthServer
26
{
27
    private $authorizationServer;
28
    private $resourceServer;
29
    private $scopePolicyManager;
30
    private $storageManager;
31
    /**
32
     * @var Config
33
     */
34
    private $config;
35
    /**
36
     * @var EndUserInterface
37
     */
38
    private $endUser;
39
40
    public function __construct(Config $config,
41
                                EndUserInterface $endUser,
42
                                ClientStorageInterface $clientStorage,
43
                                ResourceOwnerStorageInterface $resourceOwnerStorage,
44
                                AuthorizationCodeStorageInterface $authorizationCodeStorage,
45
                                AccessTokenStorageInterface $accessTokenStorage,
46
                                RefreshTokenStorageInterface $refreshTokenStorage)
47
    {
48
        $this->config = $config;
49
        $this->endUser = $endUser;
50
51
        $this->storageManager = new StorageManager(
52
            $clientStorage,
53
            $resourceOwnerStorage,
54
            $authorizationCodeStorage,
55
            $accessTokenStorage,
56
            $refreshTokenStorage
57
        );
58
59
        $this->scopePolicyManager = new ScopePolicyManager($config);
60
61
        $this->authorizationServer = $this->createAuthorizationServer();
62
        $this->resourceServer = $this->createResourceServer();
63
    }
64
65
    protected function createAuthorizationServer() {
66
        return new AuthorizationServer($this->config, $this->storageManager, $this->scopePolicyManager, $this->endUser);
67
    }
68
69
    protected function createResourceServer() {
70
        return (new ResourceServer($this->storageManager, $this->scopePolicyManager))
71
            ->addBearerAuthenticationMethod(new FormEncodedBodyParameter())
72
            ->addBearerAuthenticationMethod(new URIQueryParameter());
73
    }
74
75
    /**
76
     * @return AuthorizationServer
77
     */
78
    public function getAuthorizationServer(): AuthorizationServer
79
    {
80
        return $this->authorizationServer;
81
    }
82
83
    /**
84
     * @return ResourceServer
85
     */
86
    public function getResourceServer(): ResourceServer
87
    {
88
        return $this->resourceServer;
89
    }
90
91
92
}