Improve result page appearance
This commit is contained in:
parent
9a3c44e840
commit
e36eb7c74b
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1197,6 +1197,7 @@ dependencies = [
|
||||
"rand",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"urlencoding",
|
||||
]
|
||||
|
||||
|
@ -13,6 +13,7 @@ lazy_static = "1.4.0"
|
||||
actix-web = "4.3.1"
|
||||
askama = "0.12.0"
|
||||
serde = { version = "1.0.160", features = ["derive"] }
|
||||
serde_json = "1.0.96"
|
||||
reqwest = { version = "0.11.16", features = ["json"] }
|
||||
urlencoding = "2.1.2"
|
||||
futures-util = "0.3.28"
|
||||
|
@ -26,6 +26,10 @@ body {
|
||||
}
|
||||
|
||||
|
||||
main {
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
/*
|
||||
* Header
|
||||
*/
|
||||
|
16
src/main.rs
16
src/main.rs
@ -1,6 +1,6 @@
|
||||
use actix_web::middleware::Logger;
|
||||
use actix_web::{get, web, App, HttpResponse, HttpServer};
|
||||
use askama::Template;
|
||||
use actix_web::middleware::Logger;
|
||||
|
||||
use oidc_test_client::app_config::AppConfig;
|
||||
use oidc_test_client::openid_primitives::OpenIDConfig;
|
||||
@ -112,7 +112,7 @@ async fn redirect(remote_ip: RemoteIP, query: web::Query<RedirectQuery>) -> Http
|
||||
};
|
||||
|
||||
// Query token endpoint
|
||||
let token = match config
|
||||
let (token, token_str) = match config
|
||||
.request_token(
|
||||
&AppConfig::get().client_id,
|
||||
&AppConfig::get().client_secret,
|
||||
@ -129,7 +129,7 @@ async fn redirect(remote_ip: RemoteIP, query: web::Query<RedirectQuery>) -> Http
|
||||
};
|
||||
|
||||
// Query userinfo endpoint
|
||||
let user_info = match config.request_user_info(&token).await {
|
||||
let (_user_info, user_info_str) = match config.request_user_info(&token).await {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
log::error!("Failed to retrieve user info! {}", e);
|
||||
@ -139,8 +139,14 @@ async fn redirect(remote_ip: RemoteIP, query: web::Query<RedirectQuery>) -> Http
|
||||
|
||||
HttpResponse::Ok().content_type("text/html").body(
|
||||
ResultTemplate {
|
||||
token: format!("{:#?}", token),
|
||||
user_info: format!("{:#?}", user_info),
|
||||
token: serde_json::to_string_pretty(
|
||||
&serde_json::from_str::<serde_json::Value>(&token_str).unwrap(),
|
||||
)
|
||||
.unwrap(),
|
||||
user_info: serde_json::to_string_pretty(
|
||||
&serde_json::from_str::<serde_json::Value>(&user_info_str).unwrap(),
|
||||
)
|
||||
.unwrap(),
|
||||
}
|
||||
.render()
|
||||
.unwrap(),
|
||||
|
@ -62,7 +62,7 @@ impl OpenIDConfig {
|
||||
client_secret: &str,
|
||||
code: &str,
|
||||
redirect_uri: &str,
|
||||
) -> Res<TokenResponse> {
|
||||
) -> Res<(TokenResponse, String)> {
|
||||
let authorization = BASE64_STANDARD.encode(format!("{}:{}", client_id, client_secret));
|
||||
|
||||
let mut params = HashMap::new();
|
||||
@ -70,24 +70,28 @@ impl OpenIDConfig {
|
||||
params.insert("code", code);
|
||||
params.insert("redirect_uri", redirect_uri);
|
||||
|
||||
Ok(reqwest::Client::new()
|
||||
let response = reqwest::Client::new()
|
||||
.post(&self.token_endpoint)
|
||||
.header("Authorization", format!("Basic {authorization}"))
|
||||
.form(¶ms)
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
.await?)
|
||||
.text()
|
||||
.await?;
|
||||
|
||||
Ok((serde_json::from_str(&response)?, response))
|
||||
}
|
||||
|
||||
/// Query the UserInfo endpoint
|
||||
pub async fn request_user_info(&self, token: &TokenResponse) -> Res<UserInfo> {
|
||||
Ok(reqwest::Client::new()
|
||||
pub async fn request_user_info(&self, token: &TokenResponse) -> Res<(UserInfo, String)> {
|
||||
let response = reqwest::Client::new()
|
||||
.get(&self.userinfo_endpoint)
|
||||
.header("Authorization", format!("Bearer {}", token.access_token))
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
.await?)
|
||||
.text()
|
||||
.await?;
|
||||
|
||||
Ok((serde_json::from_str(&response)?, response))
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
<style>
|
||||
.card {
|
||||
text-align: left;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user