Implement server #3

Merged
pierre merged 5 commits from feat-server into master 2023-04-28 07:15:10 +00:00
6 changed files with 1402 additions and 21 deletions
Showing only changes of commit d14237eaca - Show all commits

1197
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,3 +10,5 @@ log = "0.4.17"
env_logger = "0.10.0" env_logger = "0.10.0"
clap = {version="4.2.4", features=["derive", "env"]} clap = {version="4.2.4", features=["derive", "env"]}
lazy_static = "1.4.0" lazy_static = "1.4.0"
actix-web = "4.3.1"
askama = "0.12.0"

6
assets/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

123
assets/cover.css Normal file
View File

@ -0,0 +1,123 @@
/*
* Globals
*/
/* Custom default button */
.btn-light,
.btn-light:hover,
.btn-light:focus {
color: #333;
text-shadow: none; /* Prevent inheritance from `body` */
}
/*
* Base structure
*/
body {
text-shadow: 0 .05rem .1rem rgba(0, 0, 0, .5);
box-shadow: inset 0 0 5rem rgba(0, 0, 0, .5);
}
.cover-container {
max-width: 42em;
}
/*
* Header
*/
.nav-masthead .nav-link {
color: rgba(255, 255, 255, .5);
border-bottom: .25rem solid transparent;
}
.nav-masthead .nav-link:hover,
.nav-masthead .nav-link:focus {
border-bottom-color: rgba(255, 255, 255, .25);
}
.nav-masthead .nav-link + .nav-link {
margin-left: 1rem;
}
.nav-masthead .active {
color: #fff;
border-bottom-color: #fff;
}
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
.b-example-divider {
width: 100%;
height: 3rem;
background-color: rgba(0, 0, 0, .1);
border: solid rgba(0, 0, 0, .15);
border-width: 1px 0;
box-shadow: inset 0 .5em 1.5em rgba(0, 0, 0, .1), inset 0 .125em .5em rgba(0, 0, 0, .15);
}
.b-example-vr {
flex-shrink: 0;
width: 1.5rem;
height: 100vh;
}
.bi {
vertical-align: -.125em;
fill: currentColor;
}
.nav-scroller {
position: relative;
z-index: 2;
height: 2.75rem;
overflow-y: hidden;
}
.nav-scroller .nav {
display: flex;
flex-wrap: nowrap;
padding-bottom: 1rem;
margin-top: -1px;
overflow-x: auto;
text-align: center;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
}
.btn-bd-primary {
--bd-violet-bg: #712cf9;
--bd-violet-rgb: 112.520718, 44.062154, 249.437846;
--bs-btn-font-weight: 600;
--bs-btn-color: var(--bs-white);
--bs-btn-bg: var(--bd-violet-bg);
--bs-btn-border-color: var(--bd-violet-bg);
--bs-btn-hover-color: var(--bs-white);
--bs-btn-hover-bg: #6528e0;
--bs-btn-hover-border-color: #6528e0;
--bs-btn-focus-shadow-rgb: var(--bd-violet-rgb);
--bs-btn-active-color: var(--bs-btn-hover-color);
--bs-btn-active-bg: #5a23c8;
--bs-btn-active-border-color: #5a23c8;
}
.bd-mode-toggle {
z-index: 1500;
}

View File

@ -1,3 +1,5 @@
use actix_web::{get, App, HttpResponse, HttpServer};
use askama::Template;
use clap::Parser; use clap::Parser;
/// Basic OpenID test client /// Basic OpenID test client
@ -24,18 +26,59 @@ struct AppConfig {
client_secret: String, client_secret: String,
} }
impl AppConfig {
pub fn redirect_url(&self) -> String {
format!("{}/redirect", self.public_url)
}
}
lazy_static::lazy_static! { lazy_static::lazy_static! {
static ref CONF: AppConfig = { static ref CONF: AppConfig = {
AppConfig::parse() AppConfig::parse()
}; };
} }
fn main() { #[get("/assets/bootstrap.min.css")]
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); async fn bootstrap() -> HttpResponse {
HttpResponse::Ok()
.content_type("text/css")
.body(include_str!("../assets/bootstrap.min.css"))
}
#[get("/assets/cover.css")]
async fn cover() -> HttpResponse {
HttpResponse::Ok()
.content_type("text/css")
.body(include_str!("../assets/cover.css"))
}
#[derive(Template)]
#[template(path = "home.html")]
struct HomeTemplate {
redirect_url: String,
}
#[get("/")]
async fn home() -> HttpResponse {
HttpResponse::Ok().content_type("text/html").body(
HomeTemplate {
redirect_url: CONF.redirect_url(),
}
.render()
.unwrap(),
)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
log::info!("Will listen on {}", CONF.listen_addr); log::info!("Will listen on {}", CONF.listen_addr);
println!("Hello, world!"); HttpServer::new(|| App::new().service(bootstrap).service(cover).service(home))
.bind(&CONF.listen_addr)
.expect("Failed to bind server!")
.run()
.await
} }
#[cfg(test)] #[cfg(test)]

44
templates/home.html Normal file
View File

@ -0,0 +1,44 @@
<!doctype html>
<html lang="en" class="h-100" data-bs-theme="auto">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="OIDC basic test client">
<meta name="author" content="Pierre HUBERT">
<title>OIDC Test client</title>
<link href="/assets/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
<link href="/assets/cover.css" rel="stylesheet" />
<meta name="theme-color" content="#712cf9">
</head>
<body class="d-flex h-100 text-center text-bg-dark">
<div class="cover-container d-flex w-100 h-100 p-3 mx-auto flex-column">
<header class="mb-auto">
<div>
<h3 class="float-md-start mb-0">OIDC test client</h3>
</div>
</header>
<main class="px-3">
<h1>Test OIDC Authentication flow.</h1>
<p class="lead">Get started testing OIDC authentication flow</p>
<p>Redirect URI: {{ redirect_url }}</p>
<p class="lead">
<a href="/start" class="btn btn-lg btn-light fw-bold border-white bg-white">Start</a>
</p>
</main>
<footer class="mt-auto text-white-50">
<p>&copy; Pierre HUBERT</p>
</footer>
</div>
</body>
</html>