-
Notifications
You must be signed in to change notification settings - Fork 2
Add support of Mercure running on a subdomain #1394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.x
Are you sure you want to change the base?
Changes from all commits
b53578c
a9b73d3
623e3a9
6b147af
d2bb9ee
63cecfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,6 @@ | |
| use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
| use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
| use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
| use Symfony\Component\HttpFoundation\Cookie; | ||
| use function is_array; | ||
| use function is_int; | ||
| use function is_null; | ||
|
|
@@ -48,12 +47,6 @@ class Configuration implements ConfigurationInterface | |
|
|
||
| private const string PERMISSION_ARRAY_VALUE_ERROR = 'Each permission value must be a boolean.'; | ||
|
|
||
| private const array ALLOWED_COOKIE_SAME_SITE_VALUES = [ | ||
| Cookie::SAMESITE_LAX, | ||
| Cookie::SAMESITE_NONE, | ||
| Cookie::SAMESITE_STRICT, | ||
| ]; | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
|
|
@@ -297,14 +290,13 @@ private function addMercureConfiguration(ArrayNodeDefinition $node): void | |
| ->info('Lifetime of the mercure cookie in seconds. Default is one hour.') | ||
| ->defaultValue(3600) | ||
| ->end() | ||
| ->enumNode('cookie_same_site') | ||
| ->info('Same site setting for the mercure cookie. Default is "' . | ||
| Cookie::SAMESITE_STRICT .'". ' . | ||
| 'Possible values are: ' . | ||
| implode(',', self::ALLOWED_COOKIE_SAME_SITE_VALUES) .'".' | ||
| ) | ||
| ->values(self::ALLOWED_COOKIE_SAME_SITE_VALUES) | ||
| ->defaultValue(Cookie::SAMESITE_STRICT) | ||
| ->scalarNode('jwt_cookie_host') | ||
| ->info('Domain where to set the Mercure auth cookie, e.g. ".example.com".') | ||
| ->defaultNull() | ||
| ->end() | ||
| ->booleanNode('jwt_cookie_strictness') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe as booleanNode might be not good if we have to consider |
||
| ->info('If true, use SameSite=Strict; if false, use SameSite=None.') | ||
| ->defaultTrue() | ||
| ->end() | ||
| ->end() | ||
| ->end(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -26,24 +26,34 @@ public function __construct( | |||||
| private TokenProviderInterface $tokenProvider, | ||||||
| private UrlServiceInterface $urlService, | ||||||
| private int $cookieLifetime = 3600, | ||||||
| private string $cookieSameSite = Cookie::SAMESITE_STRICT, | ||||||
| private bool $jwt_cookie_strictness = true, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| private ?string $jwtCookieHost = null, | ||||||
| ) { | ||||||
| } | ||||||
|
|
||||||
| public function createCookie(): Cookie | ||||||
| { | ||||||
| $urlParts = parse_url($this->urlService->getClientSideUrl()); | ||||||
|
|
||||||
| $host = ''; | ||||||
| if (!empty($this->jwtCookieHost)) { | ||||||
| $host = $this->jwtCookieHost; | ||||||
| } | ||||||
|
|
||||||
| if ($host === '' && isset($urlParts[Mercure::URL_HOST->value])) { | ||||||
| $host = $urlParts[Mercure::URL_HOST->value]; | ||||||
| } | ||||||
|
|
||||||
| return new Cookie( | ||||||
| Mercure::AUTHORIZATION_COOKIE_NAME->value, | ||||||
| $this->tokenProvider->getJwt(), | ||||||
| time() + $this->cookieLifetime, | ||||||
| $urlParts[Mercure::URL_PATH->value] ?? '/', | ||||||
| $urlParts[Mercure::URL_HOST->value] ?? '', | ||||||
| $host, | ||||||
| $urlParts[Mercure::URL_SCHEME->value] === Mercure::URL_SCHEME_HTTPS->value, | ||||||
| true, | ||||||
| false, | ||||||
| $this->cookieSameSite | ||||||
| $this->jwt_cookie_strictness ? Cookie::SAMESITE_STRICT : Cookie::SAMESITE_NONE | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ); | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to keep camelCase as the others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe even just
$cookieStrictness, it's always JWT in this context