use std::fmt;
use url::{Position, Url};
use crate::csrf::CsrfToken;
#[derive(Default)]
pub struct LoginOptions {
pub(crate) params: Vec<(String, String)>,
}
impl LoginOptions {
pub fn new() -> Self {
Self::default()
}
pub fn param(mut self, name: impl Into<String>, value: impl Into<String>) -> Self {
self.params.push((name.into(), value.into()));
self
}
}
impl fmt::Debug for LoginOptions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let names: Vec<&str> = self.params.iter().map(|(name, _)| name.as_str()).collect();
f.debug_struct("LoginOptions")
.field("params", &names)
.finish()
}
}
#[non_exhaustive]
pub struct Login {
pub url: Url,
pub csrf_token: CsrfToken,
pub pkce_verifier: String,
}
impl fmt::Debug for Login {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let base = &self.url[..Position::AfterPath];
f.debug_struct("Login")
.field("url", &format_args!("{base}?[redacted]"))
.field("csrf_token", &"[redacted]")
.field("pkce_verifier", &"[redacted]")
.finish()
}
}
#[non_exhaustive]
pub struct LoginNonPkce {
pub url: Url,
pub csrf_token: CsrfToken,
}
impl fmt::Debug for LoginNonPkce {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let base = &self.url[..Position::AfterPath];
f.debug_struct("LoginNonPkce")
.field("url", &format_args!("{base}?[redacted]"))
.field("csrf_token", &"[redacted]")
.finish()
}
}