Skip to content

Commit

Permalink
feat(server): Authorization header
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed May 10, 2024
1 parent 053578e commit f733d75
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/modules/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,28 @@ impl<'r> FromRequest<'r> for AuthGuard {
)
)));

let session_cookie = match request.cookies().get_private("session_id") {
Some(cookie) => cookie,
let session_id = match request.headers().get_one("Authorization").and_then(|v| v.split_whitespace().last()) {
Some(session_id) => session_id.to_owned(),
None => {
return rocket::request::Outcome::Error((
rocket::http::Status::Unauthorized,
AppError::unauthorized(i18n),
))
}
};

let session_id = match session_cookie.value().parse() {
Ok(session_id) => session_id,
_ => {
return rocket::request::Outcome::Error((
rocket::http::Status::Unauthorized,
AppError::unauthorized(i18n),
))
let session_cookie = match request.cookies().get_private("session_id") {
Some(cookie) => cookie,
None => {
return rocket::request::Outcome::Error((
rocket::http::Status::Unauthorized,
AppError::unauthorized(i18n),
))
}
};

match session_cookie.value().parse() {
Ok(session_id) => session_id,
_ => {
return rocket::request::Outcome::Error((
rocket::http::Status::Unauthorized,
AppError::unauthorized(i18n),
))
}
}
}
};

Expand Down

0 comments on commit f733d75

Please sign in to comment.