refactor: move jwks loading to function

This commit is contained in:
Nico Fricke 2025-01-22 19:58:05 +01:00
parent a574efb3b1
commit 8ce49f7c3d

View File

@ -7,6 +7,7 @@ mod extractor_helper;
mod files;
mod routes;
use crate::config::Config;
use axum::{middleware, Router};
use axum_jwks::Jwks;
use std::env;
@ -29,15 +30,7 @@ async fn main() {
match config {
Ok(config) => {
debug!("Config loaded {:?}", &config,);
let jwks = Jwks::from_oidc_url(
// The Authorization Server that signs the JWTs you want to consume.
&config.oidc.oidc_endpoint,
// The audience identifier for the application. This ensures that
// JWTs are intended for this application.
None,
)
.await
.unwrap();
let jwks = load_jwks(&config).await;
let bind = format!("{}:{}", &config.server.bind_address, &config.server.port);
let state = AppState { config, jwks };
let app = Router::new()
@ -63,6 +56,12 @@ async fn main() {
}
}
async fn load_jwks(config: &Config) -> Jwks {
Jwks::from_oidc_url(&config.oidc.oidc_endpoint, None)
.await
.unwrap()
}
fn get_log_level() -> tracing::Level {
let env = env::var("CASKET_LOG_LEVEL");
match env {