-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
64 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::sync::Arc; | ||
|
||
use poem::{ | ||
http::StatusCode, | ||
web::{cookie::CookieJar, Data}, | ||
Error, FromRequest, Request, RequestBody, Result, Route, | ||
}; | ||
use uuid::Uuid; | ||
|
||
use crate::state::AppState; | ||
|
||
use super::session::SessionState; | ||
|
||
pub struct AuthToken { | ||
pub session: SessionState, | ||
} | ||
|
||
impl<'a> FromRequest<'a> for AuthToken { | ||
async fn from_request(req: &'a Request, body: &mut RequestBody) -> Result<Self> { | ||
let state = Data::<&Arc<AppState>>::from_request(req, body).await?; | ||
|
||
let token = { | ||
let token = req | ||
.headers() | ||
.get("Authorization") | ||
.map(|x| x.to_str().unwrap().replace("Bearer ", "")) | ||
.expect("No token found"); | ||
Uuid::parse_str(&token).unwrap() | ||
}; | ||
|
||
let session = SessionState::get_by_id(token, &state.database) | ||
.await | ||
.unwrap(); | ||
|
||
Ok(AuthToken { session }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod oauth; | ||
pub mod session; | ||
pub mod middleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters