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; |
|
|
|
|
12
|
|
|
use League\OAuth2\Server\AuthorizationServer; |
|
|
|
|
13
|
|
|
use League\OAuth2\Server\CryptKey; |
|
|
|
|
14
|
|
|
use League\OAuth2\Server\Grant\ClientCredentialsGrant; |
|
|
|
|
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); |
|
|
|
|
52
|
|
|
$privateKeyPassword = getenv(Env::OAUTH2_PRIVATE_KEY_PASSWORD); |
|
|
|
|
53
|
|
|
$encryptionKeyRaw = getenv(Env::OAUTH2_ENCRYPTION_KEY); |
|
|
|
|
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); |
|
|
|
|
68
|
|
|
$server->enableGrantType( |
69
|
|
|
new ClientCredentialsGrant(), |
70
|
|
|
new DateInterval($expiry) |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$container->bindInstance(AuthorizationServer::class, $server); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths