diff --git a/configuration/local.yaml b/configuration/local.yaml index f5a4bba..e69886e 100644 --- a/configuration/local.yaml +++ b/configuration/local.yaml @@ -3,3 +3,6 @@ application: base_url: "http://127.0.0.1" database: require_ssl: false +jwks: + url: "http://localhost:8088/realms/test" + authority: "account" diff --git a/src/config/jwks.rs b/src/config/jwks.rs index 17caa81..1bb9c30 100644 --- a/src/config/jwks.rs +++ b/src/config/jwks.rs @@ -5,6 +5,7 @@ use jsonwebtoken::{ DecodingKey, TokenData, Validation, }; use serde::de::DeserializeOwned; +use serde::Deserialize; use std::collections::HashMap; use thiserror::Error; use tracing::{debug, info}; @@ -69,8 +70,12 @@ impl Jwks { }, ); } - _ => { - info!(%kid, "Ignoring unsupported key.") + other => { + return Err(JwkError::UnexpectedAlgorithm { + key_id: kid, + algorithm: other.to_owned(), + } + .into()) } } } @@ -156,3 +161,9 @@ pub(crate) enum JwkError { key_id: String, }, } + +#[derive(Deserialize, Clone)] +pub struct JwksSettings { + pub url: String, + pub authority: String, +} diff --git a/src/config/mod.rs b/src/config/mod.rs index a32589a..6ca3bc8 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -7,10 +7,13 @@ use app::ApplicationSettings; use database::DatabaseSettings; use serde::Deserialize; +use self::jwks::JwksSettings; + #[derive(Deserialize, Clone)] pub struct Settings { pub database: DatabaseSettings, pub application: ApplicationSettings, + pub jwks: JwksSettings, } pub fn get_configuration() -> Result { diff --git a/src/startup.rs b/src/startup.rs index eb9c5e9..67a7fc8 100644 --- a/src/startup.rs +++ b/src/startup.rs @@ -8,8 +8,7 @@ use std::net::TcpListener; pub async fn build(settings: Settings) -> anyhow::Result<()> { let api_context = ApiContext { db: settings.database.get_connection_pool(), - jwks: Jwks::from_authority("http://localhost:8088/realms/test", "account".to_string()) - .await?, + jwks: Jwks::from_authority(&settings.jwks.url, settings.jwks.authority).await?, }; let api_router = build_routes(api_context); let address = format!(