5
5
namespace Auth0 \Symfony ;
6
6
7
7
use Auth0 \SDK \Configuration \SdkConfiguration ;
8
+ use Auth0 \SDK \Contract \StoreInterface ;
8
9
use Auth0 \SDK \Token ;
9
10
use Auth0 \Symfony \Contracts \BundleInterface ;
10
11
use Auth0 \Symfony \Controllers \AuthenticationController ;
11
12
use Auth0 \Symfony \Security \{Authenticator , Authorizer , UserProvider };
12
13
use Auth0 \Symfony \Stores \SessionStore ;
14
+ use OpenSSLAsymmetricKey ;
15
+ use Psr \Cache \CacheItemPoolInterface ;
16
+ use Psr \EventDispatcher \ListenerProviderInterface ;
17
+ use Psr \Http \Client \ClientInterface ;
18
+ use Psr \Http \Message \{RequestFactoryInterface , ResponseFactoryInterface , StreamFactoryInterface };
13
19
use Symfony \Component \Config \Definition \Configurator \DefinitionConfigurator ;
14
20
use Symfony \Component \DependencyInjection \Loader \Configurator \ContainerConfigurator ;
15
21
use Symfony \Component \DependencyInjection \{ContainerBuilder , Reference };
@@ -22,56 +28,84 @@ public function configure(DefinitionConfigurator $definition): void
22
28
$ definition ->import ('../config/definition.php ' );
23
29
}
24
30
31
+ /**
32
+ * @param array<mixed> $config The configuration array.
33
+ * @param ContainerConfigurator $container The container configurator.
34
+ * @param ContainerBuilder $builder The container builder.
35
+ */
25
36
public function loadExtension (array $ config , ContainerConfigurator $ container , ContainerBuilder $ builder ): void
26
37
{
27
- $ tokenCache = $ config ['sdk ' ]['token_cache ' ] ?? 'cache.app ' ;
28
- $ tokenCache = new Reference ($ tokenCache );
38
+ $ sdkConfig = $ config ['sdk ' ] ?? [];
29
39
30
- $ managementTokenCache = $ config ['sdk ' ]['management_token_cache ' ] ?? 'cache.app ' ;
31
- $ managementTokenCache = new Reference ($ managementTokenCache );
40
+ /**
41
+ * @var array{strategy: string, domain: ?string, custom_domain: ?string, client_id: ?string, redirect_uri: ?string, client_secret: ?string, audiences: null|array<string>, organizations: null|array<string>, use_pkce: bool, scopes: null|array<string>, response_mode: string, response_type: string, token_algorithm: ?string, token_jwks_uri: ?string, token_max_age: ?int, token_leeway: ?int, token_cache: ?CacheItemPoolInterface, token_cache_ttl: int, http_client: null|ClientInterface|string, http_max_retries: int, http_request_factory: null|RequestFactoryInterface|string, http_response_factory: null|ResponseFactoryInterface|string, http_stream_factory: null|StreamFactoryInterface|string, http_telemetry: bool, session_storage: ?StoreInterface, session_storage_prefix: ?string, cookie_secret: ?string, cookie_domain: ?string, cookie_expires: int, cookie_path: string, cookie_secure: bool, cookie_same_site: ?string, persist_user: bool, persist_id_token: bool, persist_access_token: bool, persist_refresh_token: bool, transient_storage: ?StoreInterface, transient_storage_prefix: ?string, query_user_info: bool, management_token: ?string, management_token_cache: ?CacheItemPoolInterface, event_listener_provider: null|ListenerProviderInterface|string, client_assertion_signing_key: null|OpenSSLAsymmetricKey|string, client_assertion_signing_algorithm: string, pushed_authorization_request: bool, backchannel_logout_cache: ?CacheItemPoolInterface, backchannel_logout_expires: int} $sdkConfig
42
+ */
43
+ $ tokenCache = $ sdkConfig ['token_cache ' ] ?? 'cache.app ' ;
32
44
33
- $ backchannelLogoutCache = $ config ['sdk ' ]['backchannel_logout_cache ' ] ?? 'cache.app ' ;
34
- $ backchannelLogoutCache = new Reference ($ backchannelLogoutCache );
45
+ if (! $ tokenCache instanceof CacheItemPoolInterface) {
46
+ $ tokenCache = new Reference ($ tokenCache );
47
+ }
48
+
49
+ $ managementTokenCache = $ sdkConfig ['management_token_cache ' ] ?? 'cache.app ' ;
50
+
51
+ if (! $ managementTokenCache instanceof CacheItemPoolInterface) {
52
+ $ managementTokenCache = new Reference ($ managementTokenCache );
53
+ }
54
+
55
+ $ backchannelLogoutCache = $ sdkConfig ['backchannel_logout_cache ' ] ?? 'cache.app ' ;
56
+
57
+ if (! $ backchannelLogoutCache instanceof CacheItemPoolInterface) {
58
+ $ backchannelLogoutCache = new Reference ($ backchannelLogoutCache );
59
+ }
60
+
61
+ $ transientStorage = $ sdkConfig ['transient_storage ' ] ?? 'auth0.store_transient ' ;
62
+
63
+ if (! $ transientStorage instanceof StoreInterface) {
64
+ $ transientStorage = new Reference ($ transientStorage );
65
+ }
66
+
67
+ $ sessionStorage = $ sdkConfig ['session_storage ' ] ?? 'auth0.store_session ' ;
35
68
36
- $ transientStorage = new Reference ($ config ['sdk ' ]['transient_storage ' ] ?? 'auth0.store_transient ' );
37
- $ sessionStorage = new Reference ($ config ['sdk ' ]['session_storage ' ] ?? 'auth0.store_session ' );
69
+ if (! $ sessionStorage instanceof StoreInterface) {
70
+ $ sessionStorage = new Reference ($ sessionStorage );
71
+ }
38
72
39
- $ transientStoragePrefix = $ config [ ' sdk ' ] ['transient_storage_prefix ' ] ?? 'auth0_transient ' ;
40
- $ sessionStoragePrefix = $ config [ ' sdk ' ] ['session_storage_prefix ' ] ?? 'auth0_session ' ;
73
+ $ transientStoragePrefix = $ sdkConfig ['transient_storage_prefix ' ] ?? 'auth0_transient ' ;
74
+ $ sessionStoragePrefix = $ sdkConfig ['session_storage_prefix ' ] ?? 'auth0_session ' ;
41
75
42
- $ eventListenerProvider = $ config [ ' sdk ' ] ['event_listener_provider ' ] ?? null ;
76
+ $ eventListenerProvider = $ sdkConfig ['event_listener_provider ' ] ?? null ;
43
77
44
- if (null !== $ eventListenerProvider && '' !== $ eventListenerProvider ) {
78
+ if (! $ eventListenerProvider instanceof ListenerProviderInterface && '' !== $ eventListenerProvider && null !== $ eventListenerProvider ) {
45
79
$ eventListenerProvider = new Reference ($ eventListenerProvider );
46
80
}
47
81
48
- $ httpClient = $ config [ ' sdk ' ] ['http_client ' ] ?? null ;
82
+ $ httpClient = $ sdkConfig ['http_client ' ] ?? null ;
49
83
50
- if (null !== $ httpClient && '' !== $ httpClient ) {
84
+ if (! $ httpClient instanceof ClientInterface && '' !== $ httpClient && null !== $ httpClient ) {
51
85
$ httpClient = new Reference ($ httpClient );
52
86
}
53
87
54
- $ httpRequestFactory = $ config [ ' sdk ' ] ['http_request_factory ' ] ?? null ;
88
+ $ httpRequestFactory = $ sdkConfig ['http_request_factory ' ] ?? null ;
55
89
56
- if (null !== $ httpRequestFactory && '' !== $ httpRequestFactory ) {
90
+ if (! $ httpRequestFactory instanceof RequestFactoryInterface && '' !== $ httpRequestFactory && null !== $ httpRequestFactory ) {
57
91
$ httpRequestFactory = new Reference ($ httpRequestFactory );
58
92
}
59
93
60
- $ httpResponseFactory = $ config [ ' sdk ' ] ['http_response_factory ' ] ?? null ;
94
+ $ httpResponseFactory = $ sdkConfig ['http_response_factory ' ] ?? null ;
61
95
62
- if (null !== $ httpResponseFactory && '' !== $ httpResponseFactory ) {
96
+ if (! $ httpResponseFactory instanceof ResponseFactoryInterface && '' !== $ httpResponseFactory && null !== $ httpResponseFactory ) {
63
97
$ httpResponseFactory = new Reference ($ httpResponseFactory );
64
98
}
65
99
66
- $ httpStreamFactory = $ config [ ' sdk ' ] ['http_stream_factory ' ] ?? null ;
100
+ $ httpStreamFactory = $ sdkConfig ['http_stream_factory ' ] ?? null ;
67
101
68
- if (null !== $ httpStreamFactory && '' !== $ httpStreamFactory ) {
102
+ if (! $ httpStreamFactory instanceof StreamFactoryInterface && '' !== $ httpStreamFactory && null !== $ httpStreamFactory ) {
69
103
$ httpStreamFactory = new Reference ($ httpStreamFactory );
70
104
}
71
105
72
- $ audiences = $ config [ ' sdk ' ] ['audiences ' ] ?? [];
73
- $ organizations = $ config [ ' sdk ' ] ['organizations ' ] ?? [];
74
- $ scopes = $ config [ ' sdk ' ] ['scopes ' ] ?? [];
106
+ $ audiences = $ sdkConfig ['audiences ' ] ?? [];
107
+ $ organizations = $ sdkConfig ['organizations ' ] ?? [];
108
+ $ scopes = $ sdkConfig ['scopes ' ] ?? [];
75
109
76
110
if ([] === $ audiences ) {
77
111
$ audiences = null ;
@@ -88,50 +122,50 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
88
122
$ container ->services ()
89
123
->set ('auth0.configuration ' , SdkConfiguration::class)
90
124
->arg ('$configuration ' , null )
91
- ->arg ('$strategy ' , $ config [ ' sdk ' ] ['strategy ' ])
92
- ->arg ('$domain ' , $ config [ ' sdk ' ] ['domain ' ])
93
- ->arg ('$customDomain ' , $ config [ ' sdk ' ] ['custom_domain ' ])
94
- ->arg ('$clientId ' , $ config [ ' sdk ' ] ['client_id ' ])
95
- ->arg ('$redirectUri ' , $ config [ ' sdk ' ] ['redirect_uri ' ])
96
- ->arg ('$clientSecret ' , $ config [ ' sdk ' ] ['client_secret ' ])
125
+ ->arg ('$strategy ' , $ sdkConfig ['strategy ' ])
126
+ ->arg ('$domain ' , $ sdkConfig ['domain ' ])
127
+ ->arg ('$customDomain ' , $ sdkConfig ['custom_domain ' ])
128
+ ->arg ('$clientId ' , $ sdkConfig ['client_id ' ])
129
+ ->arg ('$redirectUri ' , $ sdkConfig ['redirect_uri ' ])
130
+ ->arg ('$clientSecret ' , $ sdkConfig ['client_secret ' ])
97
131
->arg ('$audience ' , $ audiences )
98
132
->arg ('$organization ' , $ organizations )
99
133
->arg ('$usePkce ' , true )
100
134
->arg ('$scope ' , $ scopes )
101
135
->arg ('$responseMode ' , 'query ' )
102
136
->arg ('$responseType ' , 'code ' )
103
- ->arg ('$tokenAlgorithm ' , $ config [ ' sdk ' ] ['token_algorithm ' ] ?? Token::ALGO_RS256 )
104
- ->arg ('$tokenJwksUri ' , $ config [ ' sdk ' ] ['token_jwks_uri ' ])
105
- ->arg ('$tokenMaxAge ' , $ config [ ' sdk ' ] ['token_max_age ' ])
106
- ->arg ('$tokenLeeway ' , $ config [ ' sdk ' ] ['token_leeway ' ] ?? 60 )
137
+ ->arg ('$tokenAlgorithm ' , $ sdkConfig ['token_algorithm ' ] ?? Token::ALGO_RS256 )
138
+ ->arg ('$tokenJwksUri ' , $ sdkConfig ['token_jwks_uri ' ])
139
+ ->arg ('$tokenMaxAge ' , $ sdkConfig ['token_max_age ' ])
140
+ ->arg ('$tokenLeeway ' , $ sdkConfig ['token_leeway ' ] ?? 60 )
107
141
->arg ('$tokenCache ' , $ tokenCache )
108
- ->arg ('$tokenCacheTtl ' , $ config [ ' sdk ' ] ['token_cache_ttl ' ])
142
+ ->arg ('$tokenCacheTtl ' , $ sdkConfig ['token_cache_ttl ' ])
109
143
->arg ('$httpClient ' , $ httpClient )
110
- ->arg ('$httpMaxRetries ' , $ config [ ' sdk ' ] ['http_max_retries ' ])
144
+ ->arg ('$httpMaxRetries ' , $ sdkConfig ['http_max_retries ' ])
111
145
->arg ('$httpRequestFactory ' , $ httpRequestFactory )
112
146
->arg ('$httpResponseFactory ' , $ httpResponseFactory )
113
147
->arg ('$httpStreamFactory ' , $ httpStreamFactory )
114
- ->arg ('$httpTelemetry ' , $ config [ ' sdk ' ] ['http_telemetry ' ])
148
+ ->arg ('$httpTelemetry ' , $ sdkConfig ['http_telemetry ' ])
115
149
->arg ('$sessionStorage ' , $ sessionStorage )
116
150
->arg ('$sessionStorageId ' , $ sessionStoragePrefix )
117
- ->arg ('$cookieSecret ' , $ config [ ' sdk ' ] ['cookie_secret ' ])
118
- ->arg ('$cookieDomain ' , $ config [ ' sdk ' ] ['cookie_domain ' ])
119
- ->arg ('$cookieExpires ' , $ config [ ' sdk ' ] ['cookie_expires ' ])
120
- ->arg ('$cookiePath ' , $ config [ ' sdk ' ] ['cookie_path ' ])
121
- ->arg ('$cookieSameSite ' , $ config [ ' sdk ' ] ['cookie_same_site ' ])
122
- ->arg ('$cookieSecure ' , $ config [ ' sdk ' ] ['cookie_secure ' ])
151
+ ->arg ('$cookieSecret ' , $ sdkConfig ['cookie_secret ' ])
152
+ ->arg ('$cookieDomain ' , $ sdkConfig ['cookie_domain ' ])
153
+ ->arg ('$cookieExpires ' , $ sdkConfig ['cookie_expires ' ])
154
+ ->arg ('$cookiePath ' , $ sdkConfig ['cookie_path ' ])
155
+ ->arg ('$cookieSameSite ' , $ sdkConfig ['cookie_same_site ' ])
156
+ ->arg ('$cookieSecure ' , $ sdkConfig ['cookie_secure ' ])
123
157
->arg ('$persistUser ' , true )
124
158
->arg ('$persistIdToken ' , true )
125
159
->arg ('$persistAccessToken ' , true )
126
160
->arg ('$persistRefreshToken ' , true )
127
161
->arg ('$transientStorage ' , $ transientStorage )
128
162
->arg ('$transientStorageId ' , $ transientStoragePrefix )
129
163
->arg ('$queryUserInfo ' , false )
130
- ->arg ('$managementToken ' , $ config [ ' sdk ' ] ['management_token ' ])
164
+ ->arg ('$managementToken ' , $ sdkConfig ['management_token ' ])
131
165
->arg ('$managementTokenCache ' , $ managementTokenCache )
132
166
->arg ('$eventListenerProvider ' , $ eventListenerProvider )
133
167
->arg ('$backchannelLogoutCache ' , $ backchannelLogoutCache )
134
- ->arg ('$backchannelLogoutExpires ' , $ config [ ' sdk ' ] ['backchannel_logout_expires ' ]);
168
+ ->arg ('$backchannelLogoutExpires ' , $ sdkConfig ['backchannel_logout_expires ' ]);
135
169
136
170
$ container ->services ()
137
171
->set ('auth0 ' , Service::class)
0 commit comments