From 8bb1c6d69cb754467b0d92a40f2ca5019ab2ce2d Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 12 Dec 2023 08:58:39 +0100 Subject: [PATCH 1/2] Fix error detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous error detection code seems to have been copied from stevenmaguire/oauth2-microsoft, but the response format for errors seem to be different when using Azure. Part of an example JSON: { "error": "invalid_client", "error_description": "[…]", … --- src/Provider/Azure.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Provider/Azure.php b/src/Provider/Azure.php index 86ac895..2cd8fa8 100644 --- a/src/Provider/Azure.php +++ b/src/Provider/Azure.php @@ -87,7 +87,7 @@ protected function checkResponse(ResponseInterface $response, $data) { if (isset($data['error'])) { throw new IdentityProviderException( - (isset($data['error']['message']) ? $data['error']['message'] : $response->getReasonPhrase()), + (isset($data['error_description']) ? $data['error_description'] : $response->getReasonPhrase()), $response->getStatusCode(), (string)$response->getBody() ); From b25e7202217e768efc8571ef13572fb8e6b00df6 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 2 Jan 2024 08:38:42 +0100 Subject: [PATCH 2/2] Update Test to match new Error Detection Aligns the test with the changes from 8bb1c6d69cb754467b0d92a40f2ca5019ab2ce2d, see PR #1 --- tests/src/Provider/AzureTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Provider/AzureTest.php b/tests/src/Provider/AzureTest.php index 1b73766..60f342e 100644 --- a/tests/src/Provider/AzureTest.php +++ b/tests/src/Provider/AzureTest.php @@ -160,7 +160,7 @@ public function testExceptionThrownWhenErrorObjectReceived(): void $postResponse = m::mock('Psr\Http\Message\ResponseInterface'); $postResponse->shouldReceive('getBody')->andReturn( - '{"error": {"code": "request_token_expired", "message": "' . $message . '"}}' + '{"error": "request_token_expired", "error_description": "' . $message . '"}' ); $postResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'json']); $postResponse->shouldReceive('getStatusCode')->andReturn(500);