Passed
Push — master ( 1d30f9...202808 )
by Peter
04:48
created

AuthorizationServerBootstrapper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 24
dl 0
loc 53
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBindings() 0 3 1
A registerBindings() 0 40 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Bootstrappers\Oauth2;
6
7
use AbterPhp\Admin\Oauth2\Repository;
8
use AbterPhp\Framework\Constant\Env;
9
use AbterPhp\Framework\Crypto\Crypto;
10
use DateInterval;
11
use Defuse\Crypto\Key;
0 ignored issues
show
Bug introduced by
The type Defuse\Crypto\Key was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use League\OAuth2\Server\AuthorizationServer;
0 ignored issues
show
Bug introduced by
The type League\OAuth2\Server\AuthorizationServer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use League\OAuth2\Server\CryptKey;
0 ignored issues
show
Bug introduced by
The type League\OAuth2\Server\CryptKey was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
0 ignored issues
show
Bug introduced by
The type League\OAuth2\Server\Grant\ClientCredentialsGrant was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Opulence\Databases\ConnectionPools\ConnectionPool;
16
use Opulence\Ioc\Bootstrappers\Bootstrapper;
17
use Opulence\Ioc\Bootstrappers\ILazyBootstrapper;
18
use Opulence\Ioc\IContainer;
19
use Opulence\Orm\Ids\Generators\UuidV4Generator;
20
21
class AuthorizationServerBootstrapper extends Bootstrapper implements ILazyBootstrapper
22
{
23
    /**
24
     * @inheritdoc
25
     */
26
    public function getBindings(): array
27
    {
28
        return [AuthorizationServer::class];
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function registerBindings(IContainer $container)
35
    {
36
        /** @var ConnectionPool $connectionPool */
37
        $connectionPool = $container->resolve(ConnectionPool::class);
38
39
        /** @var Crypto $crypto */
40
        $crypto = $container->resolve(Crypto::class);
41
42
        /** @var UuidV4Generator $uuidGenerator */
43
        $uuidGenerator = $container->resolve(UuidV4Generator::class);
44
45
        // Init our repositories
46
        $clientRepository      = new Repository\Client($crypto, $connectionPool);
47
        $scopeRepository       = new Repository\Scope($connectionPool);
48
        $accessTokenRepository = new Repository\AccessToken($uuidGenerator, $connectionPool);
49
50
        // Path to public and private keys
51
        $privateKeyPath     = getenv(Env::OAUTH2_PRIVATE_KEY_PATH);
0 ignored issues
show
Bug introduced by
The constant AbterPhp\Framework\Const...OAUTH2_PRIVATE_KEY_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
52
        $privateKeyPassword = getenv(Env::OAUTH2_PRIVATE_KEY_PASSWORD);
0 ignored issues
show
Bug introduced by
The constant AbterPhp\Framework\Const...H2_PRIVATE_KEY_PASSWORD was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
53
        $encryptionKeyRaw   = getenv(Env::OAUTH2_ENCRYPTION_KEY);
0 ignored issues
show
Bug introduced by
The constant AbterPhp\Framework\Const...::OAUTH2_ENCRYPTION_KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
54
55
        $encryptionKey = Key::loadFromAsciiSafeString($encryptionKeyRaw);
56
        $privateKey    = new CryptKey($privateKeyPath, $privateKeyPassword);
57
58
        // Setup the authorization server
59
        $server = new AuthorizationServer(
60
            $clientRepository,
61
            $accessTokenRepository,
62
            $scopeRepository,
63
            $privateKey,
64
            $encryptionKey
65
        );
66
67
        $expiry = getenv(Env::OAUTH2_TOKEN_EXPIRY);
0 ignored issues
show
Bug introduced by
The constant AbterPhp\Framework\Const...nv::OAUTH2_TOKEN_EXPIRY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
68
        $server->enableGrantType(
69
            new ClientCredentialsGrant(),
70
            new DateInterval($expiry)
71
        );
72
73
        $container->bindInstance(AuthorizationServer::class, $server);
74
    }
75
}
76