55namespace Auth0 \Symfony ;
66
77use Auth0 \SDK \Configuration \SdkConfiguration ;
8+ use Auth0 \SDK \Contract \StoreInterface ;
89use Auth0 \SDK \Token ;
910use Auth0 \Symfony \Contracts \BundleInterface ;
1011use Auth0 \Symfony \Controllers \AuthenticationController ;
1112use Auth0 \Symfony \Security \{Authenticator , Authorizer , UserProvider };
1213use 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 };
1319use Symfony \Component \Config \Definition \Configurator \DefinitionConfigurator ;
1420use Symfony \Component \DependencyInjection \Loader \Configurator \ContainerConfigurator ;
1521use Symfony \Component \DependencyInjection \{ContainerBuilder , Reference };
@@ -22,56 +28,84 @@ public function configure(DefinitionConfigurator $definition): void
2228 $ definition ->import ('../config/definition.php ' );
2329 }
2430
31+ /**
32+ * @param array<mixed> $config The configuration array.
33+ * @param ContainerConfigurator $container The container configurator.
34+ * @param ContainerBuilder $builder The container builder.
35+ */
2536 public function loadExtension (array $ config , ContainerConfigurator $ container , ContainerBuilder $ builder ): void
2637 {
27- $ tokenCache = $ config ['sdk ' ]['token_cache ' ] ?? 'cache.app ' ;
28- $ tokenCache = new Reference ($ tokenCache );
38+ $ sdkConfig = $ config ['sdk ' ] ?? [];
2939
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 ' ;
3244
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 ' ;
3568
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+ }
3872
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 ' ;
4175
42- $ eventListenerProvider = $ config [ ' sdk ' ] ['event_listener_provider ' ] ?? null ;
76+ $ eventListenerProvider = $ sdkConfig ['event_listener_provider ' ] ?? null ;
4377
44- if (null !== $ eventListenerProvider && '' !== $ eventListenerProvider ) {
78+ if (! $ eventListenerProvider instanceof ListenerProviderInterface && '' !== $ eventListenerProvider && null !== $ eventListenerProvider ) {
4579 $ eventListenerProvider = new Reference ($ eventListenerProvider );
4680 }
4781
48- $ httpClient = $ config [ ' sdk ' ] ['http_client ' ] ?? null ;
82+ $ httpClient = $ sdkConfig ['http_client ' ] ?? null ;
4983
50- if (null !== $ httpClient && '' !== $ httpClient ) {
84+ if (! $ httpClient instanceof ClientInterface && '' !== $ httpClient && null !== $ httpClient ) {
5185 $ httpClient = new Reference ($ httpClient );
5286 }
5387
54- $ httpRequestFactory = $ config [ ' sdk ' ] ['http_request_factory ' ] ?? null ;
88+ $ httpRequestFactory = $ sdkConfig ['http_request_factory ' ] ?? null ;
5589
56- if (null !== $ httpRequestFactory && '' !== $ httpRequestFactory ) {
90+ if (! $ httpRequestFactory instanceof RequestFactoryInterface && '' !== $ httpRequestFactory && null !== $ httpRequestFactory ) {
5791 $ httpRequestFactory = new Reference ($ httpRequestFactory );
5892 }
5993
60- $ httpResponseFactory = $ config [ ' sdk ' ] ['http_response_factory ' ] ?? null ;
94+ $ httpResponseFactory = $ sdkConfig ['http_response_factory ' ] ?? null ;
6195
62- if (null !== $ httpResponseFactory && '' !== $ httpResponseFactory ) {
96+ if (! $ httpResponseFactory instanceof ResponseFactoryInterface && '' !== $ httpResponseFactory && null !== $ httpResponseFactory ) {
6397 $ httpResponseFactory = new Reference ($ httpResponseFactory );
6498 }
6599
66- $ httpStreamFactory = $ config [ ' sdk ' ] ['http_stream_factory ' ] ?? null ;
100+ $ httpStreamFactory = $ sdkConfig ['http_stream_factory ' ] ?? null ;
67101
68- if (null !== $ httpStreamFactory && '' !== $ httpStreamFactory ) {
102+ if (! $ httpStreamFactory instanceof StreamFactoryInterface && '' !== $ httpStreamFactory && null !== $ httpStreamFactory ) {
69103 $ httpStreamFactory = new Reference ($ httpStreamFactory );
70104 }
71105
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 ' ] ?? [];
75109
76110 if ([] === $ audiences ) {
77111 $ audiences = null ;
@@ -88,50 +122,50 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
88122 $ container ->services ()
89123 ->set ('auth0.configuration ' , SdkConfiguration::class)
90124 ->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 ' ])
97131 ->arg ('$audience ' , $ audiences )
98132 ->arg ('$organization ' , $ organizations )
99133 ->arg ('$usePkce ' , true )
100134 ->arg ('$scope ' , $ scopes )
101135 ->arg ('$responseMode ' , 'query ' )
102136 ->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 )
107141 ->arg ('$tokenCache ' , $ tokenCache )
108- ->arg ('$tokenCacheTtl ' , $ config [ ' sdk ' ] ['token_cache_ttl ' ])
142+ ->arg ('$tokenCacheTtl ' , $ sdkConfig ['token_cache_ttl ' ])
109143 ->arg ('$httpClient ' , $ httpClient )
110- ->arg ('$httpMaxRetries ' , $ config [ ' sdk ' ] ['http_max_retries ' ])
144+ ->arg ('$httpMaxRetries ' , $ sdkConfig ['http_max_retries ' ])
111145 ->arg ('$httpRequestFactory ' , $ httpRequestFactory )
112146 ->arg ('$httpResponseFactory ' , $ httpResponseFactory )
113147 ->arg ('$httpStreamFactory ' , $ httpStreamFactory )
114- ->arg ('$httpTelemetry ' , $ config [ ' sdk ' ] ['http_telemetry ' ])
148+ ->arg ('$httpTelemetry ' , $ sdkConfig ['http_telemetry ' ])
115149 ->arg ('$sessionStorage ' , $ sessionStorage )
116150 ->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 ' ])
123157 ->arg ('$persistUser ' , true )
124158 ->arg ('$persistIdToken ' , true )
125159 ->arg ('$persistAccessToken ' , true )
126160 ->arg ('$persistRefreshToken ' , true )
127161 ->arg ('$transientStorage ' , $ transientStorage )
128162 ->arg ('$transientStorageId ' , $ transientStoragePrefix )
129163 ->arg ('$queryUserInfo ' , false )
130- ->arg ('$managementToken ' , $ config [ ' sdk ' ] ['management_token ' ])
164+ ->arg ('$managementToken ' , $ sdkConfig ['management_token ' ])
131165 ->arg ('$managementTokenCache ' , $ managementTokenCache )
132166 ->arg ('$eventListenerProvider ' , $ eventListenerProvider )
133167 ->arg ('$backchannelLogoutCache ' , $ backchannelLogoutCache )
134- ->arg ('$backchannelLogoutExpires ' , $ config [ ' sdk ' ] ['backchannel_logout_expires ' ]);
168+ ->arg ('$backchannelLogoutExpires ' , $ sdkConfig ['backchannel_logout_expires ' ]);
135169
136170 $ container ->services ()
137171 ->set ('auth0 ' , Service::class)
0 commit comments