mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2026-05-25 13:30:19 +03:00
Fix invalid refresh token response (#7105)
If the refresh token is invalid or expired we need to return a specific JSON and HTTP Status, else the clients will not logout. Fixes #7060 Closes #7080 Signed-off-by: BlackDex <black.dex@gmail.com>
This commit is contained in:
committed by
GitHub
parent
dfebee57ec
commit
0ed8ab68f7
+11
-7
@@ -2,7 +2,6 @@ use chrono::Utc;
|
|||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use rocket::{
|
use rocket::{
|
||||||
form::{Form, FromForm},
|
form::{Form, FromForm},
|
||||||
http::Status,
|
|
||||||
response::Redirect,
|
response::Redirect,
|
||||||
serde::json::Json,
|
serde::json::Json,
|
||||||
Route,
|
Route,
|
||||||
@@ -131,12 +130,14 @@ async fn login(
|
|||||||
login_result
|
login_result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return Status::Unauthorized to trigger logout
|
|
||||||
async fn _refresh_login(data: ConnectData, conn: &DbConn, ip: &ClientIp) -> JsonResult {
|
async fn _refresh_login(data: ConnectData, conn: &DbConn, ip: &ClientIp) -> JsonResult {
|
||||||
// Extract token
|
// When a refresh token is invalid or missing we need to respond with an HTTP BadRequest (400)
|
||||||
let refresh_token = match data.refresh_token {
|
// It also needs to return a json which holds at least a key `error` with the value `invalid_grant`
|
||||||
Some(token) => token,
|
// See the link below for details
|
||||||
None => err_code!("Missing refresh_token", Status::Unauthorized.code),
|
// https://github.com/bitwarden/clients/blob/2ee158e720a5e7dbe3641caf80b569e97a1dd91b/libs/common/src/services/api.service.ts#L1786-L1797
|
||||||
|
|
||||||
|
let Some(refresh_token) = data.refresh_token else {
|
||||||
|
err_json!(json!({"error": "invalid_grant"}), "Missing refresh_token")
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
@@ -147,7 +148,10 @@ async fn _refresh_login(data: ConnectData, conn: &DbConn, ip: &ClientIp) -> Json
|
|||||||
// let members = Membership::find_confirmed_by_user(&user.uuid, conn).await;
|
// let members = Membership::find_confirmed_by_user(&user.uuid, conn).await;
|
||||||
match auth::refresh_tokens(ip, &refresh_token, data.client_id, conn).await {
|
match auth::refresh_tokens(ip, &refresh_token, data.client_id, conn).await {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
err_code!(format!("Unable to refresh login credentials: {}", err.message()), Status::Unauthorized.code)
|
err_json!(
|
||||||
|
json!({"error": "invalid_grant"}),
|
||||||
|
format!("Unable to refresh login credentials: {}", err.message())
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Ok((mut device, auth_tokens)) => {
|
Ok((mut device, auth_tokens)) => {
|
||||||
// Save to update `device.updated_at` to track usage and toggle new status
|
// Save to update `device.updated_at` to track usage and toggle new status
|
||||||
|
|||||||
Reference in New Issue
Block a user