-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shield Axum: Add subprovider and user routes (#18)
- Loading branch information
1 parent
4c7682b
commit 5d4b3dd
Showing
5 changed files
with
44 additions
and
2 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
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,7 +1,11 @@ | ||
mod sign_in; | ||
mod sign_in_callback; | ||
mod sign_out; | ||
mod subproviders; | ||
mod user; | ||
|
||
pub use sign_in::*; | ||
pub use sign_in_callback::*; | ||
pub use sign_out::*; | ||
pub use subproviders::*; | ||
pub use user::*; |
10 changes: 10 additions & 0 deletions
10
packages/integrations/shield-axum/src/routes/subproviders.rs
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,10 @@ | ||
use axum::Json; | ||
use shield::{SubproviderVisualisation, User}; | ||
|
||
use crate::{error::RouteError, extract::ExtractShield}; | ||
|
||
pub async fn subproviders<U: User>( | ||
ExtractShield(shield): ExtractShield<U>, | ||
) -> Result<Json<Vec<SubproviderVisualisation>>, RouteError> { | ||
Ok(Json(shield.subprovider_visualisations().await?)) | ||
} |
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,26 @@ | ||
use axum::{ | ||
http::StatusCode, | ||
response::{IntoResponse, Response}, | ||
Json, | ||
}; | ||
use serde_json::json; | ||
use shield::User; | ||
|
||
use crate::extract::ExtractUser; | ||
|
||
pub async fn user<U: User>(ExtractUser(user): ExtractUser<U>) -> Response { | ||
// TODO: Send JSON error using some util. | ||
match user { | ||
Some(user) => { | ||
// TODO: Include email addresses. | ||
// let email_addresses = user.email_addresses().await; | ||
|
||
Json(json!({ | ||
"id": user.id(), | ||
"name": user.name(), | ||
})) | ||
.into_response() | ||
} | ||
None => (StatusCode::UNAUTHORIZED, "Unauthorized").into_response(), | ||
} | ||
} |