Skip to content

Commit 18d6ff2

Browse files
committed
Let JwtAuthorizer::new set the RSA pubkey parse error message
Allow only a subset of `JwtAuthConfig` fields to be set in config file, as we allow any members of the configuration tables to not be set in the file, and instead be set by the corresponding environment variable.
1 parent b828ef6 commit 18d6ff2

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

rust/auth-impls/src/jwt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const BEARER_PREFIX: &str = "Bearer ";
3434
impl JWTAuthorizer {
3535
/// Creates a new instance of [`JWTAuthorizer`], fails on failure to parse the PEM formatted RSA public key
3636
pub async fn new(rsa_pem: &str) -> Result<Self, String> {
37-
let jwt_issuer_key =
38-
DecodingKey::from_rsa_pem(rsa_pem.as_bytes()).map_err(|e| e.to_string())?;
37+
let jwt_issuer_key = DecodingKey::from_rsa_pem(rsa_pem.as_bytes())
38+
.map_err(|e| format!("Failed to parse the PEM formatted RSA public key: {}", e))?;
3939
Ok(Self { jwt_issuer_key })
4040
}
4141
}

rust/server/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ fn main() {
8282
std::process::exit(-1);
8383
},
8484
};
85-
let rsa_pem = rsa_pem_env.or(jwt_auth_config.map(|config| config.rsa_pem));
85+
let rsa_pem = rsa_pem_env.or(jwt_auth_config.and_then(|config| config.rsa_pem));
8686
if let Some(pem) = rsa_pem {
8787
authorizer = match JWTAuthorizer::new(pem.as_str()).await {
8888
Ok(auth) => {
8989
println!("Configured JWT authorizer with RSA public key");
9090
Some(Arc::new(auth))
9191
},
9292
Err(e) => {
93-
println!("Failed to parse the PEM formatted RSA public key: {}", e);
93+
println!("Failed to configure JWT authorizer: {}", e);
9494
std::process::exit(-1);
9595
},
9696
};

rust/server/src/util/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(crate) struct ServerConfig {
1515

1616
#[derive(Deserialize)]
1717
pub(crate) struct JwtAuthConfig {
18-
pub(crate) rsa_pem: String,
18+
pub(crate) rsa_pem: Option<String>,
1919
}
2020

2121
#[derive(Deserialize)]

0 commit comments

Comments
 (0)