mirror of
https://github.com/pfzetto/axum-oidc.git
synced 2025-01-18 04:49:03 +01:00
update dependencies
This commit is contained in:
parent
e86842c104
commit
74551fb479
5 changed files with 51 additions and 48 deletions
|
@ -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
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
thiserror = "1.0"
|
thiserror = "2.0"
|
||||||
axum-core = "0.5"
|
axum-core = "0.5"
|
||||||
axum = { version = "0.8", default-features = false, features = [ "query" ] }
|
axum = { version = "0.8", default-features = false, features = [ "query" ] }
|
||||||
tower-service = "0.3"
|
tower-service = "0.3"
|
||||||
tower-layer = "0.3"
|
tower-layer = "0.3"
|
||||||
tower-sessions = { version = "0.13", default-features = false, features = [ "axum-core" ] }
|
tower-sessions = { version = "0.14", default-features = false, features = [ "axum-core" ] }
|
||||||
http = "1.1"
|
http = "1.2"
|
||||||
openidconnect = "3.5"
|
openidconnect = "3.5"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
|
|
|
@ -6,18 +6,18 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[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 = { version = "0.8", features = [ "macros" ]}
|
||||||
axum-oidc = { path = "./../.." }
|
axum-oidc = { path = "./../.." }
|
||||||
tower = "0.4"
|
tower = "0.5"
|
||||||
tower-sessions = "0.13"
|
tower-sessions = "0.14"
|
||||||
|
|
||||||
dotenvy = "0.15"
|
dotenvy = "0.15"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
testcontainers = "0.15.0"
|
testcontainers = "0.23"
|
||||||
tokio = { version = "1.37.0", features = ["rt-multi-thread"] }
|
tokio = { version = "1.43", features = ["rt-multi-thread"] }
|
||||||
reqwest = { version = "0.12", features = ["rustls-tls"], default-features = false }
|
reqwest = { version = "0.11", features = ["rustls-tls"], default-features = false }
|
||||||
env_logger = "0.11.3"
|
env_logger = "0.11"
|
||||||
log = "0.4.21"
|
log = "0.4"
|
||||||
headless_chrome = "1.0.9"
|
headless_chrome = "1.0"
|
||||||
|
|
|
@ -64,10 +64,11 @@ async fn authenticated(claims: OidcClaims<EmptyAdditionalClaims>) -> impl IntoRe
|
||||||
format!("Hello {}", claims.subject().as_str())
|
format!("Hello {}", claims.subject().as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[axum::debug_handler]
|
||||||
async fn maybe_authenticated(
|
async fn maybe_authenticated(
|
||||||
claims: Option<OidcClaims<EmptyAdditionalClaims>>,
|
claims: Result<OidcClaims<EmptyAdditionalClaims>, axum_oidc::error::ExtractorError>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
if let Some(claims) = claims {
|
if let Ok(claims) = claims {
|
||||||
format!(
|
format!(
|
||||||
"Hello {}! You are already logged in from another Handler.",
|
"Hello {}! You are already logged in from another Handler.",
|
||||||
claims.subject().as_str()
|
claims.subject().as_str()
|
||||||
|
|
|
@ -2,7 +2,6 @@ mod keycloak;
|
||||||
|
|
||||||
use headless_chrome::Browser;
|
use headless_chrome::Browser;
|
||||||
use log::info;
|
use log::info;
|
||||||
use testcontainers::*;
|
|
||||||
|
|
||||||
use crate::keycloak::{Client, Keycloak, Realm, User};
|
use crate::keycloak::{Client, Keycloak, Realm, User};
|
||||||
|
|
||||||
|
@ -10,8 +9,6 @@ use crate::keycloak::{Client, Keycloak, Realm, User};
|
||||||
async fn first() {
|
async fn first() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let docker = clients::Cli::default();
|
|
||||||
|
|
||||||
let alice = User {
|
let alice = User {
|
||||||
username: "alice".to_string(),
|
username: "alice".to_string(),
|
||||||
email: "alice@example.com".to_string(),
|
email: "alice@example.com".to_string(),
|
||||||
|
@ -25,14 +22,11 @@ async fn first() {
|
||||||
client_secret: Some("123456".to_string()),
|
client_secret: Some("123456".to_string()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let keycloak = Keycloak::start(
|
let keycloak = Keycloak::start(vec![Realm {
|
||||||
vec![Realm {
|
name: "test".to_string(),
|
||||||
name: "test".to_string(),
|
users: vec![alice.clone()],
|
||||||
users: vec![alice.clone()],
|
clients: vec![basic_client.clone()],
|
||||||
clients: vec![basic_client.clone()],
|
}])
|
||||||
}],
|
|
||||||
&docker,
|
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
info!("starting basic example app");
|
info!("starting basic example app");
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
use log::info;
|
use log::info;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use testcontainers::*;
|
use testcontainers::runners::AsyncRunner;
|
||||||
|
use testcontainers::ContainerAsync;
|
||||||
|
|
||||||
use testcontainers::core::ExecCommand;
|
use testcontainers::core::ExecCommand;
|
||||||
use testcontainers::{core::WaitFor, Container, Image, RunnableImage};
|
use testcontainers::{core::WaitFor, Image, ImageExt};
|
||||||
|
|
||||||
struct KeycloakImage;
|
struct KeycloakImage;
|
||||||
|
|
||||||
impl Image for KeycloakImage {
|
impl Image for KeycloakImage {
|
||||||
type Args = Vec<String>;
|
fn name(&self) -> &str {
|
||||||
|
"quay.io/keycloak/keycloak"
|
||||||
fn name(&self) -> String {
|
|
||||||
"quay.io/keycloak/keycloak".to_string()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tag(&self) -> String {
|
fn tag(&self) -> &str {
|
||||||
"latest".to_string()
|
"latest"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ready_conditions(&self) -> Vec<WaitFor> {
|
fn ready_conditions(&self) -> Vec<WaitFor> {
|
||||||
|
@ -23,8 +22,8 @@ impl Image for KeycloakImage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Keycloak<'a> {
|
pub struct Keycloak {
|
||||||
container: Container<'a, KeycloakImage>,
|
container: ContainerAsync<KeycloakImage>,
|
||||||
realms: Vec<Realm>,
|
realms: Vec<Realm>,
|
||||||
url: String,
|
url: String,
|
||||||
}
|
}
|
||||||
|
@ -51,24 +50,28 @@ pub struct User {
|
||||||
pub password: String,
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Keycloak<'a> {
|
impl Keycloak {
|
||||||
pub async fn start(realms: Vec<Realm>, docker: &'a clients::Cli) -> Keycloak<'a> {
|
pub async fn start(realms: Vec<Realm>) -> Keycloak {
|
||||||
info!("starting keycloak");
|
info!("starting keycloak");
|
||||||
|
|
||||||
let keycloak_image = RunnableImage::from((KeycloakImage, vec!["start-dev".to_string()]))
|
let keycloak_image = KeycloakImage
|
||||||
.with_env_var(("KEYCLOAK_ADMIN", "admin"))
|
.with_cmd(["start-dev".to_string()])
|
||||||
.with_env_var(("KEYCLOAK_ADMIN_PASSWORD", "admin"));
|
.with_env_var("KEYCLOAK_ADMIN", "admin")
|
||||||
let container = docker.run(keycloak_image);
|
.with_env_var("KEYCLOAK_ADMIN_PASSWORD", "admin");
|
||||||
|
let container = keycloak_image.start().await.unwrap();
|
||||||
|
|
||||||
let keycloak = Self {
|
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,
|
container,
|
||||||
realms,
|
realms,
|
||||||
};
|
};
|
||||||
|
|
||||||
let issuer = format!(
|
let issuer = format!(
|
||||||
"http://127.0.0.1:{}/realms/{}",
|
"http://127.0.0.1:{}/realms/{}",
|
||||||
keycloak.container.get_host_port_ipv4(8080),
|
keycloak.container.get_host_port_ipv4(8080).await.unwrap(),
|
||||||
"test"
|
"test"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -172,9 +175,14 @@ impl<'a> Keycloak<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn execute(&self, cmd: String) {
|
async fn execute(&self, cmd: String) {
|
||||||
self.container.exec(ExecCommand {
|
let mut result = self
|
||||||
cmd,
|
.container
|
||||||
ready_conditions: vec![],
|
.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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue