Skip to content
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
24 changes: 18 additions & 6 deletions src/devicecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where
DeviceAuthorizationRequest {
auth_type: &self.auth_type,
client_id: &self.client_id,
client_secret: self.client_secret.as_ref(),
client_secret: self.client_secret.as_ref().map(Cow::Borrowed),
extra_params: Vec::new(),
scopes: Vec::new(),
device_authorization_url,
Expand All @@ -83,7 +83,7 @@ where
DeviceAccessTokenRequest {
auth_type: &self.auth_type,
client_id: &self.client_id,
client_secret: self.client_secret.as_ref(),
client_secret: self.client_secret.as_ref().map(Cow::Borrowed),
extra_params: Vec::new(),
token_url,
dev_auth_resp: auth_response,
Expand All @@ -104,7 +104,7 @@ where
{
pub(crate) auth_type: &'a AuthType,
pub(crate) client_id: &'a ClientId,
pub(crate) client_secret: Option<&'a ClientSecret>,
pub(crate) client_secret: Option<Cow<'a, ClientSecret>>,
pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>,
pub(crate) scopes: Vec<Cow<'a, Scope>>,
pub(crate) device_authorization_url: &'a DeviceAuthorizationUrl,
Expand Down Expand Up @@ -152,14 +152,20 @@ where
self
}

/// Overrides the `client_secret` to the one specified.
pub fn set_client_secret(mut self, client_secret: Cow<'a, ClientSecret>) -> Self {
self.client_secret = Some(client_secret);
self
}

fn prepare_request<RE>(self) -> Result<HttpRequest, RequestTokenError<RE, TE>>
where
RE: Error + 'static,
{
endpoint_request(
self.auth_type,
self.client_id,
self.client_secret,
self.client_secret.as_ref().map(AsRef::as_ref),
&self.extra_params,
None,
Some(&self.scopes),
Expand Down Expand Up @@ -211,7 +217,7 @@ where
{
pub(crate) auth_type: &'a AuthType,
pub(crate) client_id: &'a ClientId,
pub(crate) client_secret: Option<&'a ClientSecret>,
pub(crate) client_secret: Option<Cow<'a, ClientSecret>>,
pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>,
pub(crate) token_url: &'a TokenUrl,
pub(crate) dev_auth_resp: &'a DeviceAuthorizationResponse<EF>,
Expand Down Expand Up @@ -247,6 +253,12 @@ where
self
}

/// Overrides the `client_secret` to the one specified.
pub fn set_client_secret(mut self, client_secret: Cow<'a, ClientSecret>) -> Self {
self.client_secret = Some(client_secret);
self
}

/// Specifies a function for returning the current time.
///
/// This function is used while polling the authorization server.
Expand Down Expand Up @@ -374,7 +386,7 @@ where
endpoint_request(
self.auth_type,
self.client_id,
self.client_secret,
self.client_secret.as_ref().map(AsRef::as_ref),
&self.extra_params,
None,
None,
Expand Down
12 changes: 9 additions & 3 deletions src/introspection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ where
IntrospectionRequest {
auth_type: &self.auth_type,
client_id: &self.client_id,
client_secret: self.client_secret.as_ref(),
client_secret: self.client_secret.as_ref().map(Cow::Borrowed),
extra_params: Vec::new(),
introspection_url,
token,
Expand All @@ -83,7 +83,7 @@ where
pub(crate) token_type_hint: Option<Cow<'a, str>>,
pub(crate) auth_type: &'a AuthType,
pub(crate) client_id: &'a ClientId,
pub(crate) client_secret: Option<&'a ClientSecret>,
pub(crate) client_secret: Option<Cow<'a, ClientSecret>>,
pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>,
pub(crate) introspection_url: &'a IntrospectionUrl,
pub(crate) _phantom: PhantomData<(TE, TIR)>,
Expand Down Expand Up @@ -116,6 +116,12 @@ where
self
}

/// Overrides the `client_secret` to the one specified.
pub fn set_client_secret(mut self, client_secret: Cow<'a, ClientSecret>) -> Self {
self.client_secret = Some(client_secret);
self
}

/// Appends an extra param to the token introspection request.
///
/// This method allows extensions to be used without direct support from
Expand Down Expand Up @@ -150,7 +156,7 @@ where
endpoint_request(
self.auth_type,
self.client_id,
self.client_secret,
self.client_secret.as_ref().map(AsRef::as_ref),
&self.extra_params,
None,
None,
Expand Down
12 changes: 9 additions & 3 deletions src/revocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
Ok(RevocationRequest {
auth_type: &self.auth_type,
client_id: &self.client_id,
client_secret: self.client_secret.as_ref(),
client_secret: self.client_secret.as_ref().map(Cow::Borrowed),
extra_params: Vec::new(),
revocation_url,
token,
Expand Down Expand Up @@ -219,7 +219,7 @@ where
pub(crate) token: RT,
pub(crate) auth_type: &'a AuthType,
pub(crate) client_id: &'a ClientId,
pub(crate) client_secret: Option<&'a ClientSecret>,
pub(crate) client_secret: Option<Cow<'a, ClientSecret>>,
pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>,
pub(crate) revocation_url: &'a RevocationUrl,
pub(crate) _phantom: PhantomData<(RT, TE)>,
Expand Down Expand Up @@ -252,6 +252,12 @@ where
self
}

/// Overrides the `client_secret` to the one specified.
pub fn set_client_secret(mut self, client_secret: Cow<'a, ClientSecret>) -> Self {
self.client_secret = Some(client_secret);
self
}

fn prepare_request<RE>(self) -> Result<HttpRequest, RequestTokenError<RE, TE>>
where
RE: Error + 'static,
Expand All @@ -264,7 +270,7 @@ where
endpoint_request(
self.auth_type,
self.client_id,
self.client_secret,
self.client_secret.as_ref().map(AsRef::as_ref),
&self.extra_params,
None,
None,
Expand Down
48 changes: 36 additions & 12 deletions src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ where
ClientCredentialsTokenRequest {
auth_type: &self.auth_type,
client_id: &self.client_id,
client_secret: self.client_secret.as_ref(),
client_secret: self.client_secret.as_ref().map(Cow::Borrowed),
extra_params: Vec::new(),
scopes: Vec::new(),
token_url,
Expand All @@ -78,7 +78,7 @@ where
CodeTokenRequest {
auth_type: &self.auth_type,
client_id: &self.client_id,
client_secret: self.client_secret.as_ref(),
client_secret: self.client_secret.as_ref().map(Cow::Borrowed),
code,
extra_params: Vec::new(),
pkce_verifier: None,
Expand All @@ -97,7 +97,7 @@ where
PasswordTokenRequest {
auth_type: &self.auth_type,
client_id: &self.client_id,
client_secret: self.client_secret.as_ref(),
client_secret: self.client_secret.as_ref().map(Cow::Borrowed),
username,
password,
extra_params: Vec::new(),
Expand All @@ -115,7 +115,7 @@ where
RefreshTokenRequest {
auth_type: &self.auth_type,
client_id: &self.client_id,
client_secret: self.client_secret.as_ref(),
client_secret: self.client_secret.as_ref().map(Cow::Borrowed),
extra_params: Vec::new(),
refresh_token,
scopes: Vec::new(),
Expand All @@ -136,7 +136,7 @@ where
{
pub(crate) auth_type: &'a AuthType,
pub(crate) client_id: &'a ClientId,
pub(crate) client_secret: Option<&'a ClientSecret>,
pub(crate) client_secret: Option<Cow<'a, ClientSecret>>,
pub(crate) code: AuthorizationCode,
pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>,
pub(crate) pkce_verifier: Option<PkceCodeVerifier>,
Expand Down Expand Up @@ -187,6 +187,12 @@ where
self
}

/// Overrides the `client_secret` to the one specified.
pub fn set_client_secret(mut self, client_secret: Cow<'a, ClientSecret>) -> Self {
self.client_secret = Some(client_secret);
self
}

fn prepare_request<RE>(self) -> Result<HttpRequest, RequestTokenError<RE, TE>>
where
RE: Error + 'static,
Expand All @@ -202,7 +208,7 @@ where
endpoint_request(
self.auth_type,
self.client_id,
self.client_secret,
self.client_secret.as_ref().map(|s| s.as_ref()),
&self.extra_params,
self.redirect_url,
None,
Expand Down Expand Up @@ -247,7 +253,7 @@ where
{
pub(crate) auth_type: &'a AuthType,
pub(crate) client_id: &'a ClientId,
pub(crate) client_secret: Option<&'a ClientSecret>,
pub(crate) client_secret: Option<Cow<'a, ClientSecret>>,
pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>,
pub(crate) refresh_token: &'a RefreshToken,
pub(crate) scopes: Vec<Cow<'a, Scope>>,
Expand Down Expand Up @@ -296,6 +302,12 @@ where
self
}

/// Overrides the `client_secret` to the one specified.
pub fn set_client_secret(mut self, client_secret: Cow<'a, ClientSecret>) -> Self {
self.client_secret = Some(client_secret);
self
}

/// Synchronously sends the request to the authorization server and awaits a response.
pub fn request<C>(
self,
Expand Down Expand Up @@ -325,7 +337,7 @@ where
endpoint_request(
self.auth_type,
self.client_id,
self.client_secret,
self.client_secret.as_ref().map(AsRef::as_ref),
&self.extra_params,
None,
Some(&self.scopes),
Expand All @@ -350,7 +362,7 @@ where
{
pub(crate) auth_type: &'a AuthType,
pub(crate) client_id: &'a ClientId,
pub(crate) client_secret: Option<&'a ClientSecret>,
pub(crate) client_secret: Option<Cow<'a, ClientSecret>>,
pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>,
pub(crate) username: &'a ResourceOwnerUsername,
pub(crate) password: &'a ResourceOwnerPassword,
Expand Down Expand Up @@ -400,6 +412,12 @@ where
self
}

/// Overrides the `client_secret` to the one specified.
pub fn set_client_secret(mut self, client_secret: Cow<'a, ClientSecret>) -> Self {
self.client_secret = Some(client_secret);
self
}

/// Synchronously sends the request to the authorization server and awaits a response.
pub fn request<C>(
self,
Expand Down Expand Up @@ -430,7 +448,7 @@ where
endpoint_request(
self.auth_type,
self.client_id,
self.client_secret,
self.client_secret.as_ref().map(AsRef::as_ref),
&self.extra_params,
None,
Some(&self.scopes),
Expand All @@ -456,7 +474,7 @@ where
{
pub(crate) auth_type: &'a AuthType,
pub(crate) client_id: &'a ClientId,
pub(crate) client_secret: Option<&'a ClientSecret>,
pub(crate) client_secret: Option<Cow<'a, ClientSecret>>,
pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>,
pub(crate) scopes: Vec<Cow<'a, Scope>>,
pub(crate) token_url: &'a TokenUrl,
Expand Down Expand Up @@ -504,6 +522,12 @@ where
self
}

/// Overrides the `client_secret` to the one specified.
pub fn set_client_secret(mut self, client_secret: Cow<'a, ClientSecret>) -> Self {
self.client_secret = Some(client_secret);
self
}

/// Synchronously sends the request to the authorization server and awaits a response.
pub fn request<C>(
self,
Expand Down Expand Up @@ -534,7 +558,7 @@ where
endpoint_request(
self.auth_type,
self.client_id,
self.client_secret,
self.client_secret.as_ref().map(AsRef::as_ref),
&self.extra_params,
None,
Some(&self.scopes),
Expand Down