get jwks settings from config

This commit is contained in:
LeNei
2023-05-12 21:33:56 +02:00
parent 88dcf42286
commit aa8f3359f2
4 changed files with 20 additions and 4 deletions

View File

@@ -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"

View File

@@ -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,
}

View File

@@ -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<Settings, config::ConfigError> {

View File

@@ -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!(