mirror of
https://github.com/LeNei/axum-sqlx-template.git
synced 2026-02-13 22:56:19 +00:00
get jwks settings from config
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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!(
|
||||
|
||||
Reference in New Issue
Block a user