-
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.
Introduce Session Deauthorization & Re-org routes
- Loading branch information
Showing
10 changed files
with
235 additions
and
161 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,8 @@ | ||
use hmac::{digest::InvalidLength, Hmac, Mac}; | ||
use sha2::Sha256; | ||
|
||
pub fn hash_session(session_id: &str) -> Result<String, InvalidLength> { | ||
let mut hash = Hmac::<Sha256>::new_from_slice(b"")?; | ||
hash.update(session_id.as_bytes()); | ||
Ok(hex::encode(hash.finalize().into_bytes())) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod hash; | ||
pub mod middleware; | ||
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
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,77 @@ | ||
use std::sync::Arc; | ||
|
||
use poem:: | ||
web::{Data, Path} | ||
; | ||
use poem_openapi::{param::Query, payload::PlainText, OpenApi}; | ||
|
||
use crate::{ | ||
models::{media::Media, product::Product, property::Property}, | ||
state::AppState, | ||
}; | ||
|
||
pub struct RootApi; | ||
|
||
#[OpenApi] | ||
impl RootApi { | ||
/// Testing one two three | ||
#[oai(path = "/hello", method = "get")] | ||
async fn index(&self, name: Query<Option<String>>) -> PlainText<String> { | ||
match name.0 { | ||
Some(name) => PlainText(format!("Hello, {}!", name)), | ||
None => PlainText("Hello, World!".to_string()), | ||
} | ||
} | ||
|
||
#[oai(path = "/properties", method = "get")] | ||
async fn get_properties( | ||
&self, | ||
state: Data<&Arc<AppState>>, | ||
owner_id: Query<Option<i32>>, | ||
) -> poem_openapi::payload::Json<Vec<Property>> { | ||
let owner_id = owner_id.0.unwrap_or(0); | ||
|
||
let properties = Property::get_by_owner_id(owner_id, &state.database) | ||
.await | ||
.unwrap(); | ||
|
||
poem_openapi::payload::Json(properties) | ||
} | ||
|
||
#[oai(path = "/media/:media_id", method = "get")] | ||
async fn get_media( | ||
&self, | ||
state: Data<&Arc<AppState>>, | ||
media_id: Path<i32>, | ||
) -> poem_openapi::payload::Json<Media> { | ||
let media = Media::get_by_id(media_id.0, &state.database).await.unwrap(); | ||
|
||
poem_openapi::payload::Json(media) | ||
} | ||
|
||
#[oai(path = "/product/:product_id", method = "get")] | ||
async fn get_product( | ||
&self, | ||
state: Data<&Arc<AppState>>, | ||
product_id: Path<i32>, | ||
) -> poem_openapi::payload::Json<Product> { | ||
let product = Product::get_by_id(product_id.0, &state.database) | ||
.await | ||
.unwrap(); | ||
|
||
poem_openapi::payload::Json(product) | ||
} | ||
|
||
#[oai(path = "/property/:property_id", method = "get")] | ||
async fn get_property( | ||
&self, | ||
state: Data<&Arc<AppState>>, | ||
property_id: Path<i32>, | ||
) -> poem_openapi::payload::Json<Property> { | ||
let property = Property::get_by_id(property_id.0, &state.database) | ||
.await | ||
.unwrap(); | ||
|
||
poem_openapi::payload::Json(property) | ||
} | ||
} |
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
Oops, something went wrong.