(self)
| 435 | |
| 436 | impl IntoResponse for AuthorizationRejection { |
| 437 | fn into_response(self) -> axum::response::Response { |
| 438 | // Most likely, the server key was rotated. |
| 439 | const ROTATED: (StatusCode, &str) = ( |
| 440 | StatusCode::UNAUTHORIZED, |
| 441 | "Authorization failed: token not signed by this instance", |
| 442 | ); |
| 443 | // The JWT is malformed, see SpacetimeCreds for specifics on the format. |
| 444 | const INVALID: (StatusCode, &str) = (StatusCode::BAD_REQUEST, "Authorization is invalid: malformed token"); |
| 445 | // Sensible fallback if no auth header is present. |
| 446 | const REQUIRED: (StatusCode, &str) = (StatusCode::UNAUTHORIZED, "Authorization required"); |
| 447 | |
| 448 | log::trace!("Authorization rejection: {self:?}"); |
| 449 | |
| 450 | match self { |
| 451 | AuthorizationRejection::Jwt(e) if *e.kind() == JwtErrorKind::InvalidSignature => ROTATED.into_response(), |
| 452 | AuthorizationRejection::Jwt(_) | AuthorizationRejection::Header(_) => INVALID.into_response(), |
| 453 | AuthorizationRejection::Custom(msg) => (StatusCode::UNAUTHORIZED, msg.to_string()).into_response(), |
| 454 | AuthorizationRejection::Required => REQUIRED.into_response(), |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | impl SpacetimeAuthHeader { |
no test coverage detected