-
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.
Orca: Add session api and other authorization related improvements. (…
…#88)
- Loading branch information
1 parent
148534c
commit ef81663
Showing
5 changed files
with
77 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use rocket::{Route, State}; | ||
|
||
use super::Response; | ||
use crate::db::DbPool; | ||
use crate::server::keycloak::{JwtClaims, JwtToken, Keycloak}; | ||
use jsonwebtoken::TokenData; | ||
use rocket::serde::{json::Json, Serialize}; | ||
|
||
#[derive(Debug, Serialize)] | ||
struct SessionInfo { | ||
token_claims: JwtClaims, | ||
} | ||
|
||
impl SessionInfo { | ||
fn new(token: TokenData<JwtClaims>) -> Self { | ||
Self { | ||
token_claims: token.claims, | ||
} | ||
} | ||
} | ||
|
||
#[get("/current", format = "json")] | ||
async fn current<'r>( | ||
_db_pool: &State<DbPool>, | ||
keycloak: &State<Keycloak>, | ||
token: JwtToken<'r>, | ||
) -> Response<Json<SessionInfo>> { | ||
let token_data = keycloak.inner().decode_jwt(token)?; | ||
|
||
let session_info = SessionInfo::new(token_data); | ||
|
||
Ok(Json(session_info)) | ||
} | ||
|
||
pub fn routes() -> Vec<Route> { | ||
routes![current] | ||
} |
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