Merge branch 'oidc-content-type-issue' into development
Some checks failed
analyse-php / build (push) Has been cancelled
lint-php / build (push) Has been cancelled
test-php / build (8.1) (push) Has been cancelled
test-php / build (8.2) (push) Has been cancelled
test-migrations / build (8.1) (push) Has been cancelled
test-migrations / build (8.2) (push) Has been cancelled
test-migrations / build (8.3) (push) Has been cancelled
test-php / build (8.3) (push) Has been cancelled

This commit is contained in:
Dan Brown 2024-11-28 16:58:55 +00:00
commit 978acecdcf
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 17 additions and 1 deletions

View File

@ -11,7 +11,9 @@ class OidcUserinfoResponse implements ProvidesClaims
public function __construct(ResponseInterface $response, string $issuer, array $keys) public function __construct(ResponseInterface $response, string $issuer, array $keys)
{ {
$contentType = $response->getHeader('Content-Type')[0]; $contentTypeHeaderValue = $response->getHeader('Content-Type')[0] ?? '';
$contentType = strtolower(trim(explode(';', $contentTypeHeaderValue, 2)[0]));
if ($contentType === 'application/json') { if ($contentType === 'application/json') {
$this->claims = json_decode($response->getBody()->getContents(), true); $this->claims = json_decode($response->getBody()->getContents(), true);
} }

View File

@ -787,6 +787,20 @@ class OidcTest extends TestCase
$this->assertTrue($user->hasRole($roleA->id)); $this->assertTrue($user->hasRole($roleA->id));
} }
public function test_userinfo_endpoint_response_with_complex_json_content_type_handled()
{
$userinfoResponseData = [
'sub' => OidcJwtHelper::defaultPayload()['sub'],
'name' => 'Barry',
];
$userinfoResponse = new Response(200, ['Content-Type' => 'Application/Json ; charset=utf-8'], json_encode($userinfoResponseData));
$resp = $this->runLogin(['name' => null], [$userinfoResponse]);
$resp->assertRedirect('/');
$user = User::where('email', OidcJwtHelper::defaultPayload()['email'])->first();
$this->assertEquals('Barry', $user->name);
}
public function test_userinfo_endpoint_jwks_response_handled() public function test_userinfo_endpoint_jwks_response_handled()
{ {
$userinfoResponseData = OidcJwtHelper::idToken(['name' => 'Barry Jwks']); $userinfoResponseData = OidcJwtHelper::idToken(['name' => 'Barry Jwks']);