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 files;
mod routes; mod routes;
use crate::config::Config;
use axum::{middleware, Router}; use axum::{middleware, Router};
use axum_jwks::Jwks; use axum_jwks::Jwks;
use std::env; use std::env;
@ -29,15 +30,7 @@ async fn main() {
match config { match config {
Ok(config) => { Ok(config) => {
debug!("Config loaded {:?}", &config,); debug!("Config loaded {:?}", &config,);
let jwks = Jwks::from_oidc_url( let jwks = load_jwks(&config).await;
// 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 bind = format!("{}:{}", &config.server.bind_address, &config.server.port); let bind = format!("{}:{}", &config.server.bind_address, &config.server.port);
let state = AppState { config, jwks }; let state = AppState { config, jwks };
let app = Router::new() 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 { fn get_log_level() -> tracing::Level {
let env = env::var("CASKET_LOG_LEVEL"); let env = env::var("CASKET_LOG_LEVEL");
match env { match env {