diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-10-07 19:11:24 -0400 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-10-07 19:11:24 -0400 |
commit | 4ae9a69badb2356c01ee181600db444021d21e0d (patch) | |
tree | 8609cc9ed351ef2825568a6388316bf91294ff22 | |
parent | c64a7a640ac8c59eb6339f0a06d2ad2efab3fd11 (diff) |
Downgrade to stable axum to use tower-cookies
-rw-r--r-- | Cargo.lock | 28 | ||||
-rw-r--r-- | server/Cargo.toml | 2 | ||||
-rw-r--r-- | server/src/main.rs | 37 |
3 files changed, 31 insertions, 36 deletions
@@ -102,12 +102,12 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.6.0-rc.2" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2628a243073c55aef15a1c1fe45c87f21b84f9e89ca9e7b262a180d3d03543d" +checksum = "c9e3356844c4d6a6d6467b8da2cffb4a2820be256f50a3a386c9d152bab31043" dependencies = [ "async-trait", - "axum-core 0.3.0-rc.2", + "axum-core", "bitflags", "bytes", "futures-util", @@ -148,22 +148,6 @@ dependencies = [ ] [[package]] -name = "axum-core" -version = "0.3.0-rc.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "473bd0762170028bb6b5068be9e97de2a9f0af3bf2084498d840498f47194d3d" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http", - "http-body", - "mime", - "tower-layer", - "tower-service", -] - -[[package]] name = "base64" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -858,9 +842,9 @@ dependencies = [ [[package]] name = "matchit" -version = "0.6.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dfc802da7b1cf80aefffa0c7b2f77247c8b32206cc83c270b61264f5b360a80" +checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" [[package]] name = "memchr" @@ -1693,7 +1677,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19833e336396f3953e5ab1513d72b5e5ea51d5ad39b78d306766a05740b48b97" dependencies = [ "async-trait", - "axum-core 0.2.8", + "axum-core", "cookie", "futures-util", "http", diff --git a/server/Cargo.toml b/server/Cargo.toml index f25aa4c..41d3081 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -axum = "0.6.0-rc.2" +axum = "0.5" dotenv = "0.15.0" serde = { version = "1.0.145", features = ["derive"] } serde_json = "1.0.85" diff --git a/server/src/main.rs b/server/src/main.rs index 994c291..d2a33a5 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,15 +1,22 @@ -use std::{env, sync::Arc}; +use std::{env, sync::Arc, collections::HashMap}; -use axum::{extract::{FromRequest, Extension}, routing::get, Json, Router, http::{Request, request::Parts}, body::Body}; +use axum::{ + body::Body, + extract::{Extension, FromRequest, Query}, + http::{request::Parts, Request}, + routing::get, + Json, Router, +}; use openidconnect::{ core::{CoreClient, CoreProviderMetadata, CoreResponseType}, reqwest::async_http_client, + url::Url, AccessTokenHash, AuthenticationFlow, AuthorizationCode, ClientId, ClientSecret, CsrfToken, - IssuerUrl, Nonce, OAuth2TokenResponse, PkceCodeChallenge, RedirectUrl, Scope, TokenResponse, url::Url, + IssuerUrl, Nonce, OAuth2TokenResponse, PkceCodeChallenge, RedirectUrl, Scope, TokenResponse, }; use protocol::UserInfo; -use tower_http::trace::TraceLayer; use tower_cookies::{Cookie, CookieManagerLayer, Cookies}; +use tower_http::trace::TraceLayer; use tracing::{info, trace}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; mod auth; @@ -35,9 +42,7 @@ async fn keycloak_client( let client = CoreClient::from_provider_metadata(provider_metadata, client_id, Some(client_secret)) // Set the URL the user will be redirected to after the authorization process. - .set_redirect_uri( - redirect_uri - ); + .set_redirect_uri(redirect_uri); client } @@ -60,7 +65,7 @@ async fn main() { let state = Arc::new(ServerContext { app_url: app_url, - authenticator: Authenticator::from_env().await, + authenticator: Authenticator::from_env().await, }); let app = Router::new() @@ -81,14 +86,20 @@ async fn user_info() -> Json<Option<UserInfo>> { Json(None) } -async fn login_callback(mut req: Parts) -> &'static str { - info!("{req:?}"); - "hello" +async fn login_callback( + cookies: Cookies, + Query(params): Query<HashMap<String, String>>, +) -> () { + info!("{params:?}"); + () } -async fn get_login_url(extension: ContextExtension) -> Json<Url> { +async fn get_login_url(cookies: Cookies, extension: ContextExtension) -> Json<Url> { let (user_id, auth_url) = extension.authenticator.get_login_url().await; trace!("Creating auth url for {user_id:?}"); - // cookies.add(Cookie::new("user-id", serde_json::to_string(user_id))); + cookies.add(Cookie::new( + "user-id", + serde_json::to_string(&user_id).unwrap(), + )); Json(auth_url) } |