mirror of
https://github.com/dani-garcia/vaultwarden.wiki.git
synced 2026-09-17 15:36:20 +03:00
Fix iOS registration token response (#7714)
* Return registration token as text/plain for Accept: */* * fix register verification response content negotiation
This commit is contained in:
+13
-2
@@ -3,7 +3,7 @@ use num_traits::FromPrimitive;
|
|||||||
use rocket::{
|
use rocket::{
|
||||||
Route,
|
Route,
|
||||||
form::{Form, FromForm},
|
form::{Form, FromForm},
|
||||||
http::{Cookie, CookieJar, SameSite},
|
http::{Accept, Cookie, CookieJar, MediaType, SameSite},
|
||||||
response::Redirect,
|
response::Redirect,
|
||||||
serde::json::Json,
|
serde::json::Json,
|
||||||
};
|
};
|
||||||
@@ -1083,11 +1083,18 @@ enum RegisterVerificationResponse {
|
|||||||
#[response(status = 204)]
|
#[response(status = 204)]
|
||||||
NoContent(()),
|
NoContent(()),
|
||||||
Token(Json<String>),
|
Token(Json<String>),
|
||||||
|
PlainToken(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return JSON only when the client explicitly requests it, otherwise return plain text.
|
||||||
|
fn accepts_json(accept: Option<&Accept>) -> bool {
|
||||||
|
accept.is_some_and(|accept| accept.preferred().media_type() == &MediaType::JSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/accounts/register/send-verification-email", data = "<data>")]
|
#[post("/accounts/register/send-verification-email", data = "<data>")]
|
||||||
async fn register_verification_email(
|
async fn register_verification_email(
|
||||||
data: Json<RegisterVerificationData>,
|
data: Json<RegisterVerificationData>,
|
||||||
|
accept: Option<&Accept>,
|
||||||
ip: ClientIp,
|
ip: ClientIp,
|
||||||
conn: DbConn,
|
conn: DbConn,
|
||||||
) -> ApiResult<RegisterVerificationResponse> {
|
) -> ApiResult<RegisterVerificationResponse> {
|
||||||
@@ -1125,7 +1132,11 @@ async fn register_verification_email(
|
|||||||
} else {
|
} else {
|
||||||
// If email verification is not required, return the token directly
|
// If email verification is not required, return the token directly
|
||||||
// the clients will use this token to finish the registration
|
// the clients will use this token to finish the registration
|
||||||
Ok(RegisterVerificationResponse::Token(Json(token)))
|
Ok(if accepts_json(accept) {
|
||||||
|
RegisterVerificationResponse::Token(Json(token))
|
||||||
|
} else {
|
||||||
|
RegisterVerificationResponse::PlainToken(token)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user