Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 37f75b1

Browse filesBrowse files
rebase from symfony#48285
1 parent c678fe4 commit 37f75b1
Copy full SHA for 37f75b1

File tree

2 files changed

+11
-9
lines changed
Filter options

2 files changed

+11
-9
lines changed

‎src/Symfony/Component/Security/Http/AccessToken/Oidc/OidcUserInfoTokenHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/AccessToken/Oidc/OidcUserInfoTokenHandler.php
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1616
use Symfony\Component\Security\Http\AccessToken\AccessTokenHandlerInterface;
1717
use Symfony\Component\Security\Http\AccessToken\Oidc\Exception\InvalidOidcUserException;
18+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
1819
use Symfony\Contracts\HttpClient\HttpClientInterface;
1920

2021
/**
@@ -25,27 +26,27 @@
2526
final class OidcUserInfoTokenHandler implements AccessTokenHandlerInterface
2627
{
2728
public function __construct(
28-
private HttpClientInterface $oidcClient,
29-
private ?LoggerInterface $logger = null,
30-
private string $claim = 'sub',
31-
private string $userinfoUrl = 'protocol/openid-connect/userinfo'
29+
private HttpClientInterface $client,
30+
private ?LoggerInterface $logger = null,
31+
private string $claim = 'sub',
32+
private string $userinfoUrl = 'protocol/openid-connect/userinfo'
3233
) {
3334
}
3435

35-
public function getUserIdentifierFrom(string $accessToken): string
36+
public function getUserBadgeFrom(string $accessToken): UserBadge
3637
{
3738
try {
3839
// Call the OIDC server to retrieve the user info
3940
// If the token is invalid or expired, the OIDC server will return an error
40-
$userinfo = $this->oidcClient->request('GET', $this->userinfoUrl, [
41+
$userinfo = $this->client->request('GET', $this->userinfoUrl, [
4142
'auth_bearer' => $accessToken,
4243
])->toArray();
4344

4445
if (empty($userinfo[$this->claim])) {
4546
throw new InvalidOidcUserException(sprintf('"%s" property not found on OIDC server response.', $this->claim));
4647
}
4748

48-
return (string) $userinfo[$this->claim];
49+
return new UserBadge($userinfo[$this->claim]);
4950
} catch (\Throwable $e) {
5051
$this->logger?->error('An error occurred on OIDC server.', [
5152
'error' => $e->getMessage(),

‎src/Symfony/Component/Security/Http/Tests/AccessToken/Oidc/OidcUserInfoTokenHandlerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Tests/AccessToken/Oidc/OidcUserInfoTokenHandlerTest.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Psr\Log\LoggerInterface;
1616
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1717
use Symfony\Component\Security\Http\AccessToken\Oidc\OidcUserInfoTokenHandler;
18+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
1819
use Symfony\Contracts\HttpClient\HttpClientInterface;
1920
use Symfony\Contracts\HttpClient\ResponseInterface;
2021

@@ -38,7 +39,7 @@ public function testGetsUserIdentifierFromOidcServerResponse(string $claim): voi
3839
->willReturn($responseMock);
3940

4041
$handler = new OidcUserInfoTokenHandler($clientMock, null, $claim);
41-
$this->assertSame((string) $response[$claim], $handler->getUserIdentifierFrom('a-secret-token'));
42+
$this->assertEquals(new UserBadge($response[$claim]), $handler->getUserBadgeFrom('a-secret-token'));
4243
}
4344

4445
public function getClaims(): iterable
@@ -69,6 +70,6 @@ public function testThrowsAnExceptionIfUserPropertyIsMissing(): void
6970
->method('error');
7071

7172
$handler = new OidcUserInfoTokenHandler($clientMock, $loggerMock);
72-
$handler->getUserIdentifierFrom('a-secret-token');
73+
$handler->getUserBadgeFrom('a-secret-token');
7374
}
7475
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.