Skip to content

Commit b32a657

Browse files
committed
Return HTTP 401 when token is missing
When the repository returns an HTTP 401 error, flatpak is supposed to request a token (if it hasn't already) using the authenticator. However, we currently return a 403, which causes the transaction to fail instead.
1 parent 7bfca06 commit b32a657

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ pub enum ApiError {
117117

118118
#[fail(display = "NotEnoughPermissions")]
119119
NotEnoughPermissions(String),
120+
121+
#[fail(display = "TokenRequired")]
122+
TokenRequired,
120123
}
121124

122125
impl From<DieselError> for ApiError {
@@ -182,6 +185,11 @@ impl ApiError {
182185
"error-type": "token-insufficient",
183186
"message": format!("Not enough permissions: {}", message),
184187
}),
188+
ApiError::TokenRequired => json!({
189+
"status": 401,
190+
"error-type": "token-required",
191+
"message": "Token required"
192+
}),
185193
}
186194
}
187195

@@ -196,6 +204,7 @@ impl ApiError {
196204
ApiError::WrongPublishedState(_, _, _) => StatusCode::BAD_REQUEST,
197205
ApiError::InvalidToken(_) => StatusCode::UNAUTHORIZED,
198206
ApiError::NotEnoughPermissions(ref _message) => StatusCode::FORBIDDEN,
207+
ApiError::TokenRequired => StatusCode::UNAUTHORIZED,
199208
}
200209
}
201210
}

src/tokens.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ impl ClaimsValidator for HttpRequest {
7474
if let Some(claims) = self.extensions().get::<Claims>() {
7575
func(claims)
7676
} else {
77-
Err(ApiError::NotEnoughPermissions(
78-
"No token specified".to_string(),
79-
))
77+
Err(ApiError::TokenRequired)
8078
}
8179
}
8280

0 commit comments

Comments
 (0)