use std::collections::HashMap;
use josekit::jwk::Jwk;
use serde_json::Value;
use super::GrantExtras;
pub struct GrantParams<'a> {
pub body: HashMap<String, String>,
pub extras: GrantExtras<'a>,
pub retry: bool,
}
impl Default for GrantParams<'_> {
fn default() -> Self {
Self {
body: HashMap::new(),
extras: Default::default(),
retry: true,
}
}
}
impl<'a> GrantParams<'a> {
pub fn add_body_param(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.body.insert(key.into(), value.into());
self
}
pub fn set_grant_type(mut self, value: impl Into<String>) -> Self {
self.body.insert("grant_type".to_string(), value.into());
self
}
pub fn set_scopes(mut self, value: impl Into<String>) -> Self {
self.body.insert("scope".to_string(), value.into());
self
}
pub fn set_dpop_key(mut self, dpop: &'a Jwk) -> Self {
self.extras.dpop = Some(dpop);
self
}
pub fn set_auth_method(mut self, eam: &'a str) -> Self {
self.extras.endpoint_auth_method = Some(eam);
self
}
pub fn add_client_assertion_claim(mut self, key: impl Into<String>, value: Value) -> Self {
match self.extras.client_assertion_payload.as_mut() {
Some(cap) => {
cap.insert(key.into(), value);
}
None => {
let mut new = HashMap::new();
new.insert(key.into(), value);
self.extras.client_assertion_payload = Some(new);
}
}
self
}
pub fn retry(mut self, retry: bool) -> Self {
self.retry = retry;
self
}
}