-
SummaryI have the following middleware: pub async fn authorize(
State(state): State<AuthState>,
auth_header: Option<TypedHeader<Authorization<Basic>>>,
req: Request,
next: Next,
) -> Result<Response, UnauthorizedError> {
// ...
} And when I try to call it with the following headers:
The headers fail to decode and returns a 400 error without me being able to handle this case in the code. Instead, if I encode the credentials in base64 and make the call again with headers:
The middleware then is able to decode the Basic auth header and my code gets executed. Is there a way to have control over the case when the auth headers fail to decode? Because in that case I would like to return an UNAUTHORIZED error instead of BAD_REQUEST Thank you :) axum version0.8.4 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Can you use a |
Beta Was this translation helpful? Give feedback.
-
Alternatively, you can use WithRejection to just map the rejection during extraction. |
Beta Was this translation helpful? Give feedback.
Can you use a
Result
instead of anOption
?