1
0
Fork 0
mirror of https://github.com/dani-garcia/vaultwarden.git synced 2025-08-30 14:34:48 +00:00

move Duo API endpoint fmt strings out of macros and into format! calls

This commit is contained in:
0x0fbc 2024-07-20 16:18:03 -04:00
commit 33658387ac

View file

@ -19,32 +19,6 @@ use crate::{
}; };
use url::Url; use url::Url;
// Duo OIDC Auth API URL constants. Defined as macros, so they can be passed into format!()
#[allow(non_snake_case)]
macro_rules! HEALTH_ENDPOINT {
() => {
"https://{}/oauth/v1/health_check"
};
}
#[allow(non_snake_case)]
macro_rules! AUTHZ_ENDPOINT {
() => {
"https://{}/oauth/v1/authorize"
};
}
#[allow(non_snake_case)]
macro_rules! API_HOST_FMT {
() => {
"https://{}"
};
}
#[allow(non_snake_case)]
macro_rules! TOKEN_ENDPOINT {
() => {
"https://{}/oauth/v1/token"
};
}
// The location on this service that Duo should redirect users to. For us, this is a bridge // The location on this service that Duo should redirect users to. For us, this is a bridge
// built in to the Bitwarden clients. // built in to the Bitwarden clients.
// See: https://github.com/bitwarden/clients/blob/main/apps/web/src/connectors/duo-redirect.ts // See: https://github.com/bitwarden/clients/blob/main/apps/web/src/connectors/duo-redirect.ts
@ -173,7 +147,7 @@ impl DuoClient {
// are up. // are up.
// https://duo.com/docs/oauthapi#health-check // https://duo.com/docs/oauthapi#health-check
async fn health_check(&self) -> Result<(), Error> { async fn health_check(&self) -> Result<(), Error> {
let health_check_url: String = format!(HEALTH_ENDPOINT!(), self.api_host); let health_check_url: String = format!("https://{}/oauth/v1/health_check", self.api_host);
let jwt_payload = self.new_client_assertion(&health_check_url); let jwt_payload = self.new_client_assertion(&health_check_url);
@ -233,7 +207,7 @@ impl DuoClient {
state, state,
duo_uname: String::from(duo_username), duo_uname: String::from(duo_username),
iss: self.client_id.clone(), iss: self.client_id.clone(),
aud: format!(API_HOST_FMT!(), self.api_host), aud: format!("https://{}", self.api_host),
nonce, nonce,
}; };
@ -242,7 +216,7 @@ impl DuoClient {
Err(e) => return Err(e), Err(e) => return Err(e),
}; };
let authz_endpoint = format!(AUTHZ_ENDPOINT!(), self.api_host); let authz_endpoint = format!("https://{}/oauth/v1/authorize", self.api_host);
let mut auth_url = match Url::parse(authz_endpoint.as_str()) { let mut auth_url = match Url::parse(authz_endpoint.as_str()) {
Ok(url) => url, Ok(url) => url,
Err(e) => err!(format!("Error parsing Duo authorization URL: {e:?}")), Err(e) => err!(format!("Error parsing Duo authorization URL: {e:?}")),
@ -272,7 +246,7 @@ impl DuoClient {
err!("Empty Duo authorization code") err!("Empty Duo authorization code")
} }
let token_url = format!(TOKEN_ENDPOINT!(), self.api_host); let token_url = format!("https://{}/oauth/v1/token", self.api_host);
let jwt_payload = self.new_client_assertion(&token_url); let jwt_payload = self.new_client_assertion(&token_url);