-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOAuth2FrameworkServerBundle.php
More file actions
114 lines (102 loc) · 4.33 KB
/
OAuth2FrameworkServerBundle.php
File metadata and controls
114 lines (102 loc) · 4.33 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace OAuth2Framework\ServerBundle;
use OAuth2Framework\ServerBundle\Component\Core\TrustedIssuerSource;
use OAuth2Framework\ServerBundle\Component\Core\ClientSource;
use OAuth2Framework\ServerBundle\Component\Core\AccessTokenSource;
use OAuth2Framework\ServerBundle\Component\Core\UserAccountSource;
use OAuth2Framework\ServerBundle\Component\Core\ServicesSource;
use OAuth2Framework\ServerBundle\Component\Core\ResourceServerSource;
use OAuth2Framework\ServerBundle\Component\ClientRule\ClientRuleSource;
use OAuth2Framework\ServerBundle\Component\ClientAuthentication\ClientAuthenticationSource;
use OAuth2Framework\ServerBundle\Component\Scope\ScopeSource;
use OAuth2Framework\ServerBundle\Component\TokenType\TokenTypeSource;
use OAuth2Framework\ServerBundle\Component\Endpoint\EndpointSource;
use OAuth2Framework\ServerBundle\Component\Grant\GrantSource;
use OAuth2Framework\ServerBundle\Component\OpenIdConnect\OpenIdConnectSource;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
use OAuth2Framework\Component\AuthorizationCodeGrant\AbstractAuthorizationCode;
use OAuth2Framework\Component\ClientRegistrationEndpoint\AbstractInitialAccessToken;
use OAuth2Framework\Component\RefreshTokenGrant\AbstractRefreshToken;
use OAuth2Framework\ServerBundle\DependencyInjection\OAuth2FrameworkExtension;
use function Safe\realpath;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class OAuth2FrameworkServerBundle extends Bundle
{
/**
* @var Component\Component[]
*/
private array $components = [];
public function __construct()
{
foreach ($this->getComponents() as $component) {
$this->components[$component->name()] = $component;
}
}
public function getContainerExtension(): ExtensionInterface
{
return new OAuth2FrameworkExtension('oauth2_server', $this->components);
}
public function build(ContainerBuilder $container): void
{
parent::build($container);
foreach ($this->components as $component) {
$component->build($container);
}
$this->loadDoctrineSchemas($container);
}
private function loadDoctrineSchemas(ContainerBuilder $container): void
{
if (!class_exists(DoctrineOrmMappingsPass::class)) {
return;
}
$map = [
realpath(__DIR__.'/Resources/config/doctrine-mapping/AccessToken') => 'OAuth2Framework\Component\Core\AccessToken',
realpath(__DIR__.'/Resources/config/doctrine-mapping/Client') => 'OAuth2Framework\Component\Core\Client',
];
if (class_exists(AbstractAuthorizationCode::class)) {
$map[realpath(__DIR__.'/Resources/config/doctrine-mapping/AuthorizationCodeGrant')] = 'OAuth2Framework\Component\AuthorizationCodeGrant';
}
if (class_exists(AbstractInitialAccessToken::class)) {
$map[realpath(__DIR__.'/Resources/config/doctrine-mapping/ClientRegistrationEndpoint')] = 'OAuth2Framework\Component\ClientRegistrationEndpoint';
}
if (class_exists(AbstractRefreshToken::class)) {
$map[realpath(__DIR__.'/Resources/config/doctrine-mapping/RefreshTokenGrant')] = 'OAuth2Framework\Component\RefreshTokenGrant';
}
$container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($map));
}
/**
* @return Component\Component[]
*/
private function getComponents(): array
{
return [
new TrustedIssuerSource(),
new ClientSource(),
new AccessTokenSource(),
new UserAccountSource(),
new ServicesSource(),
new ResourceServerSource(),
new ClientRuleSource(),
new ClientAuthenticationSource(),
new ScopeSource(),
new TokenTypeSource(),
new EndpointSource(),
new GrantSource(),
new OpenIdConnectSource(),
/*
new Component\HttpSource(),
new Component\KeySet(),*/
];
}
}