update dependencies

This commit is contained in:
Paul Zinselmeyer 2025-01-12 22:37:30 +01:00
parent e86842c104
commit 74551fb479
Signed by: pfzetto
GPG key ID: B471A1AF06C895FD
5 changed files with 51 additions and 48 deletions

View file

@ -12,13 +12,13 @@ keywords = [ "axum", "oidc", "openidconnect", "authentication" ]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
thiserror = "1.0"
thiserror = "2.0"
axum-core = "0.5"
axum = { version = "0.8", default-features = false, features = [ "query" ] }
tower-service = "0.3"
tower-layer = "0.3"
tower-sessions = { version = "0.13", default-features = false, features = [ "axum-core" ] }
http = "1.1"
tower-sessions = { version = "0.14", default-features = false, features = [ "axum-core" ] }
http = "1.2"
openidconnect = "3.5"
serde = "1.0"
futures-util = "0.3"

View file

@ -6,18 +6,18 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1.37", features = ["net", "macros", "rt-multi-thread"] }
tokio = { version = "1.43", features = ["net", "macros", "rt-multi-thread"] }
axum = { version = "0.8", features = [ "macros" ]}
axum-oidc = { path = "./../.." }
tower = "0.4"
tower-sessions = "0.13"
tower = "0.5"
tower-sessions = "0.14"
dotenvy = "0.15"
[dev-dependencies]
testcontainers = "0.15.0"
tokio = { version = "1.37.0", features = ["rt-multi-thread"] }
reqwest = { version = "0.12", features = ["rustls-tls"], default-features = false }
env_logger = "0.11.3"
log = "0.4.21"
headless_chrome = "1.0.9"
testcontainers = "0.23"
tokio = { version = "1.43", features = ["rt-multi-thread"] }
reqwest = { version = "0.11", features = ["rustls-tls"], default-features = false }
env_logger = "0.11"
log = "0.4"
headless_chrome = "1.0"

View file

@ -64,10 +64,11 @@ async fn authenticated(claims: OidcClaims<EmptyAdditionalClaims>) -> impl IntoRe
format!("Hello {}", claims.subject().as_str())
}
#[axum::debug_handler]
async fn maybe_authenticated(
claims: Option<OidcClaims<EmptyAdditionalClaims>>,
claims: Result<OidcClaims<EmptyAdditionalClaims>, axum_oidc::error::ExtractorError>,
) -> impl IntoResponse {
if let Some(claims) = claims {
if let Ok(claims) = claims {
format!(
"Hello {}! You are already logged in from another Handler.",
claims.subject().as_str()

View file

@ -2,7 +2,6 @@ mod keycloak;
use headless_chrome::Browser;
use log::info;
use testcontainers::*;
use crate::keycloak::{Client, Keycloak, Realm, User};
@ -10,8 +9,6 @@ use crate::keycloak::{Client, Keycloak, Realm, User};
async fn first() {
env_logger::init();
let docker = clients::Cli::default();
let alice = User {
username: "alice".to_string(),
email: "alice@example.com".to_string(),
@ -25,14 +22,11 @@ async fn first() {
client_secret: Some("123456".to_string()),
};
let keycloak = Keycloak::start(
vec![Realm {
let keycloak = Keycloak::start(vec![Realm {
name: "test".to_string(),
users: vec![alice.clone()],
clients: vec![basic_client.clone()],
}],
&docker,
)
}])
.await;
info!("starting basic example app");

View file

@ -1,21 +1,20 @@
use log::info;
use std::time::Duration;
use testcontainers::*;
use testcontainers::runners::AsyncRunner;
use testcontainers::ContainerAsync;
use testcontainers::core::ExecCommand;
use testcontainers::{core::WaitFor, Container, Image, RunnableImage};
use testcontainers::{core::WaitFor, Image, ImageExt};
struct KeycloakImage;
impl Image for KeycloakImage {
type Args = Vec<String>;
fn name(&self) -> String {
"quay.io/keycloak/keycloak".to_string()
fn name(&self) -> &str {
"quay.io/keycloak/keycloak"
}
fn tag(&self) -> String {
"latest".to_string()
fn tag(&self) -> &str {
"latest"
}
fn ready_conditions(&self) -> Vec<WaitFor> {
@ -23,8 +22,8 @@ impl Image for KeycloakImage {
}
}
pub struct Keycloak<'a> {
container: Container<'a, KeycloakImage>,
pub struct Keycloak {
container: ContainerAsync<KeycloakImage>,
realms: Vec<Realm>,
url: String,
}
@ -51,24 +50,28 @@ pub struct User {
pub password: String,
}
impl<'a> Keycloak<'a> {
pub async fn start(realms: Vec<Realm>, docker: &'a clients::Cli) -> Keycloak<'a> {
impl Keycloak {
pub async fn start(realms: Vec<Realm>) -> Keycloak {
info!("starting keycloak");
let keycloak_image = RunnableImage::from((KeycloakImage, vec!["start-dev".to_string()]))
.with_env_var(("KEYCLOAK_ADMIN", "admin"))
.with_env_var(("KEYCLOAK_ADMIN_PASSWORD", "admin"));
let container = docker.run(keycloak_image);
let keycloak_image = KeycloakImage
.with_cmd(["start-dev".to_string()])
.with_env_var("KEYCLOAK_ADMIN", "admin")
.with_env_var("KEYCLOAK_ADMIN_PASSWORD", "admin");
let container = keycloak_image.start().await.unwrap();
let keycloak = Self {
url: format!("http://127.0.0.1:{}", container.get_host_port_ipv4(8080),),
url: format!(
"http://127.0.0.1:{}",
container.get_host_port_ipv4(8080).await.unwrap()
),
container,
realms,
};
let issuer = format!(
"http://127.0.0.1:{}/realms/{}",
keycloak.container.get_host_port_ipv4(8080),
keycloak.container.get_host_port_ipv4(8080).await.unwrap(),
"test"
);
@ -172,9 +175,14 @@ impl<'a> Keycloak<'a> {
}
async fn execute(&self, cmd: String) {
self.container.exec(ExecCommand {
cmd,
ready_conditions: vec![],
});
let mut result = self
.container
.exec(ExecCommand::new(
["/bin/sh", "-c", cmd.as_str()].iter().copied(),
))
.await
.unwrap();
// collect stdout to wait until command completion
let _output = String::from_utf8(result.stdout_to_vec().await.unwrap());
}
}