Skip to content

Commit

Permalink
feature #189 Add response message when not authenticated (VincentLang…
Browse files Browse the repository at this point in the history
…let)

This PR was squashed before being merged into the 0.4-dev branch.

Discussion
----------

Add response message when not authenticated

Hi `@chalasr`

This give something more friendly message in case of errors.

From
<img width="475" alt="image" src="https://github.com/thephpleague/oauth2-server-bundle/assets/9052536/a699fcf7-7345-49a1-8c05-0fc9281d82a5">
To
![image](https://github.com/thephpleague/oauth2-server-bundle/assets/9052536/937bddc1-140a-41d2-a4ec-0c8495aa8c3b)

Can consider it
Closes #188

Commits
-------

d554d8d Add response message when not authenticated
  • Loading branch information
chalasr committed Aug 12, 2024
2 parents 58d4b11 + d554d8d commit 94ef76e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Security/Authenticator/OAuth2Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function supports(Request $request): ?bool

public function start(Request $request, ?AuthenticationException $authException = null): Response
{
return new Response('', 401, ['WWW-Authenticate' => 'Bearer']);
return new Response($authException?->getMessage() ?? 'Authentication required', 401, ['WWW-Authenticate' => 'Bearer']);
}

/**
Expand Down

0 comments on commit 94ef76e

Please sign in to comment.