forked from commune-sh/commune-rs
-
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.
Merge pull request #1 from commune-os/main
merge: token aware routes with middleware (commune-sh#14)
- Loading branch information
Showing
21 changed files
with
354 additions
and
67 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
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
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,26 +1,30 @@ | ||
pub mod email; | ||
pub mod login; | ||
pub mod root; | ||
pub mod session; | ||
pub mod verify_code; | ||
pub mod verify_code_email; | ||
|
||
use axum::routing::{get, post}; | ||
use axum::Router; | ||
use axum::{middleware, Router}; | ||
|
||
use crate::services::SharedServices; | ||
use crate::router::middleware::auth; | ||
|
||
pub struct Account; | ||
|
||
impl Account { | ||
pub fn routes() -> Router<SharedServices> { | ||
let verify = Router::new() | ||
.route("/code", post(verify_code::handler)) | ||
.route("/code/email", post(verify_code_email::handler)); | ||
|
||
pub fn routes() -> Router { | ||
Router::new() | ||
.route("/session", get(session::handler)) | ||
.route_layer(middleware::from_fn(auth)) | ||
.route("/", post(root::handler)) | ||
.route("/email/:email", get(email::handler)) | ||
.route("/login", post(login::handler)) | ||
.nest("/verify", verify) | ||
.route("/email/:email", get(email::handler)) | ||
.nest( | ||
"/verify", | ||
Router::new() | ||
.route("/code", post(verify_code::handler)) | ||
.route("/code/email", post(verify_code_email::handler)), | ||
) | ||
} | ||
} |
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,46 @@ | ||
use axum::response::{IntoResponse, Response}; | ||
use axum::{Extension, Json}; | ||
use serde::{Deserialize, Serialize}; | ||
use tracing::instrument; | ||
|
||
use commune::account::model::Account; | ||
|
||
use crate::router::middleware::AccessToken; | ||
|
||
use super::root::{AccountMatrixCredentials, AccountSpace}; | ||
|
||
#[instrument(skip(account))] | ||
pub async fn handler( | ||
Extension(account): Extension<Account>, | ||
Extension(access_token): Extension<AccessToken>, | ||
) -> Response { | ||
let response = Json(AccountSessionResponse { | ||
credentials: AccountMatrixCredentials { | ||
username: account.username, | ||
display_name: account.display_name, | ||
avatar_url: account.avatar_url, | ||
access_token: access_token.to_string(), | ||
matrix_access_token: access_token.to_string(), | ||
matrix_user_id: account.user_id.to_string(), | ||
matrix_device_id: String::new(), | ||
user_space_id: String::new(), | ||
email: account.email, | ||
age: account.age, | ||
admin: account.admin, | ||
verified: account.verified, | ||
}, | ||
rooms: vec![], | ||
spaces: vec![], | ||
valid: true, | ||
}); | ||
|
||
response.into_response() | ||
} | ||
|
||
#[derive(Debug, Clone, Default, Deserialize, Serialize)] | ||
pub struct AccountSessionResponse { | ||
pub credentials: AccountMatrixCredentials, | ||
pub rooms: Vec<String>, | ||
pub spaces: Vec<AccountSpace>, | ||
pub valid: bool, | ||
} |
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
Oops, something went wrong.