From aca89d1c385ebec5d0596d1eb28e80e5df274809 Mon Sep 17 00:00:00 2001 From: Paul Wagener Date: Fri, 15 Nov 2024 13:37:38 +0100 Subject: [PATCH] Add BasicAuthNoEscape AuthType Can be used for servers that do not follow the specification --- src/endpoint.rs | 10 +++++++++- src/lib.rs | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/endpoint.rs b/src/endpoint.rs index a46772f..4ae2e05 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -126,7 +126,15 @@ pub(crate) fn endpoint_request<'a>( HeaderValue::from_str(&format!("Basic {}", &b64_credential)).unwrap(), ); } - (AuthType::RequestBody, _) | (AuthType::BasicAuth, None) => { + (AuthType::BasicAuthNoEscape, Some(secret)) => { + let b64_credential = + BASE64_STANDARD.encode(format!("{}:{}", &client_id.as_str(), &secret.secret())); + builder = builder.header( + AUTHORIZATION, + HeaderValue::from_str(&format!("Basic {}", &b64_credential)).unwrap(), + ); + } + (AuthType::RequestBody, _) | (AuthType::BasicAuth | AuthType::BasicAuthNoEscape, None) => { params.push(("client_id", client_id)); if let Some(client_secret) = client_secret { params.push(("client_secret", client_secret.secret())); diff --git a/src/lib.rs b/src/lib.rs index f5ffc79..15b0184 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -589,6 +589,9 @@ pub enum AuthType { RequestBody, /// The client_id and client_secret will be included using the basic auth authentication scheme. BasicAuth, + /// Same as BasicAuth but does not url escape the client_id and client_secret prior to base64 encoding + /// This can be used for server implementations that are not strictly compliant with the specification + BasicAuthNoEscape, } /// Error type returned by built-in HTTP clients when requests fail.