-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add whoami endpoint that can be hit by either user or automation token
Also factors authorization so that all authorization types (and WS vs. non-WS) all run through the same extractors
- Loading branch information
Showing
9 changed files
with
395 additions
and
147 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,38 @@ | ||
use axum::{response::IntoResponse, routing::get, Json, Router}; | ||
use dal::{UserPk, WorkspacePk}; | ||
use serde::{Deserialize, Serialize}; | ||
use si_jwt_public_key::SiJwt; | ||
|
||
use crate::{ | ||
extract::{AuthorizedForAutomationRole, EndpointAuthorization, ValidatedToken}, | ||
AppState, | ||
}; | ||
|
||
pub fn routes() -> Router<AppState> { | ||
Router::new().route("/", get(whoami)) | ||
} | ||
|
||
#[derive(Deserialize, Serialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
struct WhoamiResponse { | ||
pub user_id: UserPk, | ||
pub user_email: String, | ||
pub workspace_id: WorkspacePk, | ||
pub token: SiJwt, | ||
} | ||
|
||
async fn whoami( | ||
// Just because this is the most permissive role we have right now | ||
_: AuthorizedForAutomationRole, | ||
ValidatedToken(token): ValidatedToken, | ||
EndpointAuthorization { | ||
workspace_id, user, .. | ||
}: EndpointAuthorization, | ||
) -> impl IntoResponse { | ||
Json(WhoamiResponse { | ||
workspace_id, | ||
user_id: user.pk(), | ||
user_email: user.email().clone(), | ||
token, | ||
}) | ||
} |
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