integrate axum_oidc api changes

This commit is contained in:
Paul Zinselmeyer 2023-04-21 23:32:11 +02:00
parent e08fa51637
commit 3024f344b0
Signed by: pfzetto
GPG key ID: 4EEF46A5B276E648
2 changed files with 18 additions and 23 deletions

7
Cargo.lock generated
View file

@ -161,12 +161,11 @@ dependencies = [
[[package]] [[package]]
name = "axum_oidc" name = "axum_oidc"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.zettoit.eu/pfz4/axum_oidc#75ed3b861a85cd18d8473a65cc6a90bc38528527" source = "git+https://git.zettoit.eu/pfz4/axum_oidc#428399951cc2d70a2bf5f0f4e8a84cf7cc142feb"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum", "axum",
"axum-extra", "axum-extra",
"cookie",
"openidconnect", "openidconnect",
"reqwest", "reqwest",
"serde", "serde",
@ -235,9 +234,9 @@ dependencies = [
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.12.0" version = "3.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" checksum = "9b1ce199063694f33ffb7dd4e0ee620741495c32833cde5aa08f02a0bf96f0c8"
[[package]] [[package]]
name = "byteorder" name = "byteorder"

View file

@ -65,24 +65,13 @@ impl IntoResponse for Error {
pub struct AppState { pub struct AppState {
path: String, path: String,
application_base: String, application_base: String,
issuer: String, oidc_application: OidcApplication<EmptyAdditionalClaims>,
client_id: String,
client_secret: Option<String>,
scopes: Vec<String>,
expire: Arc<Mutex<BTreeMap<NaiveDateTime, String>>>, expire: Arc<Mutex<BTreeMap<NaiveDateTime, String>>>,
key: Key,
} }
impl FromRef<AppState> for OidcApplication { impl FromRef<AppState> for OidcApplication<EmptyAdditionalClaims> {
fn from_ref(input: &AppState) -> Self { fn from_ref(input: &AppState) -> Self {
OidcApplication::new( input.oidc_application.clone()
input.application_base.to_string(),
input.issuer.to_string(),
input.client_id.to_string(),
input.client_secret.to_owned(),
input.scopes.clone(),
input.key.clone(),
)
} }
} }
@ -107,15 +96,22 @@ async fn main() {
load_expire("data", &mut expire).await; load_expire("data", &mut expire).await;
} }
let oidc_application = OidcApplication::<EmptyAdditionalClaims>::create(
application_base.parse().unwrap(),
issuer.to_string(),
client_id.to_string(),
client_secret.to_owned(),
scopes.clone(),
Key::generate(),
)
.await
.unwrap();
let state: AppState = AppState { let state: AppState = AppState {
path: "data".to_string(), path: "data".to_string(),
application_base, application_base,
issuer, oidc_application,
client_id,
client_secret,
scopes,
expire: expire.clone(), expire: expire.clone(),
key: Key::generate(),
}; };
tokio::spawn(async move { expire_thread("data".to_string(), expire).await }); tokio::spawn(async move { expire_thread("data".to_string(), expire).await });