Conversation
0999b67 to
ed731d8
Compare
…nfirmationMiddleware Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
ed731d8 to
85070ea
Compare
| if ($this->isPasswordConfirmationStrict($reflectionMethod)) { | ||
| $authHeader = $this->request->getHeader('Authorization'); | ||
| // If no Authorization header is set, we cannot confirm the password | ||
| if (empty($authHeader) || !str_starts_with($authHeader, 'Basic ')) { |
There was a problem hiding this comment.
| if (empty($authHeader) || !str_starts_with($authHeader, 'Basic ')) { | |
| if (!str_starts_with($authHeader, 'Basic ')) { |
A string is always returned, so this is enough
| $authHeader = $this->request->getHeader('Authorization'); | ||
| // If no Authorization header is set, we cannot confirm the password | ||
| if (empty($authHeader) || !str_starts_with($authHeader, 'Basic ')) { | ||
| throw new \Exception('Missing or invalid Authorization header', Http::STATUS_BAD_REQUEST); |
There was a problem hiding this comment.
| throw new \Exception('Missing or invalid Authorization header', Http::STATUS_BAD_REQUEST); | |
| throw new \Exception('Missing or invalid Authorization header', Http::STATUS_UNAUTHORIZED); |
There was a problem hiding this comment.
No, this is on purpose to differentiate.
We expect an auth header, if it'snot here, this is a bad request
There was a problem hiding this comment.
But if you don't send the header at all, you will also get an empty string. I think HTTP semantics wise 401 is correct, but I get why you want to use 400.
There was a problem hiding this comment.
Which is ok? I actually wanna catch the lack of header ! 🙂
There was a problem hiding this comment.
I think you need to add an afterException method to the middleware to translate its exception into an response (so that is has the HTTP code you want).
For that you should use your own Exception class and test against it in afterException.
See
|
Superseded by 8b0a3a7 |
I don't see why that would happen, but this should help us investigate #53472