Skip to content
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

Fix error detection #1

Merged
merged 2 commits into from
Jan 3, 2024
Merged

Fix error detection #1

merged 2 commits into from
Jan 3, 2024

Conversation

lukasmerk
Copy link
Contributor

@lukasmerk lukasmerk commented Dec 12, 2023

Currently, the code doesn't contain error messages from the Azure backend for me.

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. The JSON in the body looks like this for me:

{
    "error": "invalid_client",
    "error_description": "AADSTS50011: The redirect URI … [redacted for privacy]",
    "error_codes": [
        50011
    ],
    "timestamp": "2023-12-11 11:06:35Z",
    "trace_id": "[redacted for privacy]",
    "correlation_id": "[redacted for privacy]",
    "error_uri": "https://login.microsoftonline.com/error?code=50011"
}

I changed the code which creates the Exception accordingly, and this works for me. The Exception previously only had a generic "Bad Request" error message, with the change it is the one from Azure.

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": "[…]",
…
@greew
Copy link
Owner

greew commented Jan 1, 2024

Great catch - the tests fails thogh.

In tests/src/Provider/AzureTest.php can you change line 162-164 from

$postResponse->shouldReceive('getBody')->andReturn(
    '{"error": {"code": "request_token_expired", "message": "' . $message . '"}}'
);

to

$postResponse->shouldReceive('getBody')->andReturn(
    '{"error": "request_token_expired", "error_description": "' . $message . '"}'
);

Aligns the test with the changes from 8bb1c6d, see PR greew#1
@lukasmerk
Copy link
Contributor Author

Thanks for your feedback! I updated the tests accordingly.

@greew greew merged commit 025c9ca into greew:main Jan 3, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants