Skip to content

Commit 7e9f36e

Browse files
Fix isAnonymous() always returning false on Symfony 6.x (#1240)
* Fix isAnonymous() always returning false on Symfony 6.x IS_AUTHENTICATED_ANONYMOUSLY was removed from AuthenticatedVoter in Symfony 6.x (deprecated since 5.4). When using #[GQL\Access('isAnonymous()')] on a Provider field, the access check always returned false, causing every request to get "Access denied to this field" regardless of auth state. PUBLIC_ACCESS is the correct replacement since Symfony 5.4 and has the same semantics: it always grants access. * Update IsAnonymousTest for Symfony 6.x PUBLIC_ACCESS change
1 parent 76d9709 commit 7e9f36e

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

src/Security/Security.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function hasRole(string $role): bool
104104

105105
public function isAnonymous(): bool
106106
{
107-
return $this->isGranted('IS_AUTHENTICATED_ANONYMOUSLY');
107+
return $this->isGranted('PUBLIC_ACCESS');
108108
}
109109

110110
public function isAuthenticated(): bool

tests/ExpressionLanguage/ExpressionFunction/Security/IsAnonymousTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ protected function getFunctions()
1717

1818
public function testEvaluator(): void
1919
{
20-
$security = $this->getSecurityIsGrantedWithExpectation(
21-
'IS_AUTHENTICATED_ANONYMOUSLY',
22-
$this->any()
23-
);
20+
$security = $this->getSecurityIsGrantedWithExpectation('PUBLIC_ACCESS', $this->any());
2421
$services = $this->createGraphQLServices(['security' => $security]);
2522

2623
$isAnonymous = $this->expressionLanguage->evaluate('isAnonymous()', [TypeGenerator::GRAPHQL_SERVICES => $services]);
@@ -29,6 +26,6 @@ public function testEvaluator(): void
2926

3027
public function testIsAnonymous(): void
3128
{
32-
$this->assertExpressionCompile('isAnonymous()', 'IS_AUTHENTICATED_ANONYMOUSLY');
29+
$this->assertExpressionCompile('isAnonymous()', 'PUBLIC_ACCESS');
3330
}
3431
}

0 commit comments

Comments
 (0)