Skip to content

Commit 7c4dff1

Browse files
committed
Merge branch 'main' of https://github.com/auth0/symfony
2 parents 0f39e9c + 50d63b5 commit 7c4dff1

15 files changed

+410
-95
lines changed

.version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.2.0
1+
5.2.1

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## [5.2.1](https://github.com/auth0/symfony/tree/5.2.1) (2023-12-16)
4+
[Full Changelog](https://github.com/auth0/symfony/compare/5.2.0...5.2.1)
5+
6+
**Fixed**
7+
- Restore method signatures [\#174](https://github.com/auth0/symfony/pull/174) ([evansims](https://github.com/evansims))
8+
39
## [5.2.0](https://github.com/auth0/symfony/tree/5.2.0) (2023-12-12)
410

511
**Added**

phpstan.neon.dist

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ parameters:
1919
- '#Cannot call method purge\(\) on Auth0\\SDK\\Contract\\StoreInterface\|null.#'
2020
- '#Casting to string something that(.*) already string.#'
2121
- '#\$object_or_class of function method_exists expects object\|string, (.*) given.#'
22+
- '#Property (.*) is never read, only written.#'
23+
- '#Call to function is_string\(\) with string will always evaluate to true.$#'
2224
-
2325
message: '#Parameter \#3 \$(.*) of function openssl_verify expects (.*), (.*) given.#'
2426
path: src\Token\Verifier.php
@@ -48,3 +50,4 @@ parameters:
4850
path: src\Utility\HttpRequest.php
4951

5052
reportUnmatchedIgnoredErrors: false
53+
checkGenericClassInNonGenericObjectType: false

psalm.xml.dist

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
>
1111
<projectFiles>
1212
<directory name="src" />
13-
14-
<ignoreFiles>
15-
<file name="src/Utility/Assert.php" />
16-
</ignoreFiles>
1713
</projectFiles>
1814

1915
<issueHandlers>

src/Auth0Bundle.php

+78-44
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
namespace Auth0\Symfony;
66

77
use Auth0\SDK\Configuration\SdkConfiguration;
8+
use Auth0\SDK\Contract\StoreInterface;
89
use Auth0\SDK\Token;
910
use Auth0\Symfony\Contracts\BundleInterface;
1011
use Auth0\Symfony\Controllers\AuthenticationController;
1112
use Auth0\Symfony\Security\{Authenticator, Authorizer, UserProvider};
1213
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};
1319
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
1420
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
1521
use 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)

src/Controllers/AuthenticationController.php

+25-2
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,30 @@
77
use Auth0\SDK\Auth0;
88
use Auth0\Symfony\Contracts\Controllers\AuthenticationControllerInterface;
99
use Auth0\Symfony\Security\Authenticator;
10+
use Psr\Container\ContainerInterface;
1011
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
12+
use Symfony\Component\HttpFoundation\Exception\{BadRequestException, ConflictingHeadersException, SuspiciousOperationException};
1113
use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response};
1214
use Symfony\Component\Routing\RouterInterface;
1315
use Throwable;
1416

17+
use function is_array;
18+
use function is_string;
19+
1520
final class AuthenticationController extends AbstractController implements AuthenticationControllerInterface
1621
{
1722
public function __construct(
1823
private Authenticator $authenticator,
1924
private RouterInterface $router,
25+
protected ContainerInterface $container,
2026
) {
2127
}
2228

29+
/**
30+
* @psalm-suppress InternalMethod
31+
*
32+
* @param Request $request
33+
*/
2334
public function callback(Request $request): Response
2435
{
2536
$host = $request->getSchemeAndHttpHost();
@@ -31,7 +42,10 @@ public function callback(Request $request): Response
3142
$code = $request->get('code');
3243
$state = $request->get('state');
3344

34-
if (null !== $code && null !== $state) {
45+
$code = is_string($code) ? trim($code) : '';
46+
$state = is_string($state) ? trim($state) : '';
47+
48+
if ('' !== $code && '' !== $state) {
3549
$route = $this->getRedirectUrl('success');
3650

3751
try {
@@ -50,6 +64,10 @@ public function callback(Request $request): Response
5064
}
5165
}
5266

67+
/**
68+
* @var string $redirect
69+
*/
70+
5371
return new RedirectResponse($redirect);
5472
}
5573

@@ -87,9 +105,14 @@ public function logout(Request $request): Response
87105
private function getRedirectUrl(string $route): string
88106
{
89107
$routes = $this->authenticator->configuration['routes'] ?? [];
108+
109+
if (! is_array($routes)) {
110+
$routes = [];
111+
}
112+
90113
$route = $routes[$route] ?? null;
91114

92-
if (null !== $route && '' !== $route) {
115+
if (is_string($route) && '' !== $route) {
93116
try {
94117
return $this->router->generate($route);
95118
} catch (Throwable) {

src/Controllers/BackchannelLogoutController.php

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Auth0\SDK\Auth0;
88
use Auth0\Symfony\Contracts\Controllers\AuthenticationControllerInterface;
99
use Auth0\Symfony\Security\Authenticator;
10+
use Psr\Container\ContainerInterface;
1011
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1112
use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response};
1213
use Throwable;
@@ -17,9 +18,15 @@ final class BackchannelLogoutController extends AbstractController implements Au
1718
{
1819
public function __construct(
1920
private Authenticator $authenticator,
21+
protected ContainerInterface $container,
2022
) {
2123
}
2224

25+
/**
26+
* @psalm-suppress InternalMethod
27+
*
28+
* @param Request $request
29+
*/
2330
public function handle(Request $request): Response
2431
{
2532
if ('POST' !== $request->getMethod()) {

src/Models/Stateful/User.php

+3
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88

99
class User extends \Auth0\Symfony\Models\User implements UserInterface
1010
{
11+
/**
12+
* @var array<string>
13+
*/
1114
protected array $roleAuthenticatedUsing = ['ROLE_USING_SESSION'];
1215
}

src/Models/Stateless/User.php

+3
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88

99
class User extends \Auth0\Symfony\Models\User implements UserInterface
1010
{
11+
/**
12+
* @var array<string>
13+
*/
1114
protected array $roleAuthenticatedUsing = ['ROLE_USING_TOKEN'];
1215
}

0 commit comments

Comments
 (0)