Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BasicAuthNoEscape AuthType #290

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down