diff --git a/src/devicecode.rs b/src/devicecode.rs index 543dcc2..4d638b3 100644 --- a/src/devicecode.rs +++ b/src/devicecode.rs @@ -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, @@ -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, @@ -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>, pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>, pub(crate) scopes: Vec>, pub(crate) device_authorization_url: &'a DeviceAuthorizationUrl, @@ -152,6 +152,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(self) -> Result> where RE: Error + 'static, @@ -159,7 +165,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), @@ -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>, pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>, pub(crate) token_url: &'a TokenUrl, pub(crate) dev_auth_resp: &'a DeviceAuthorizationResponse, @@ -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. @@ -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, diff --git a/src/introspection.rs b/src/introspection.rs index a40166f..e116b5a 100644 --- a/src/introspection.rs +++ b/src/introspection.rs @@ -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, @@ -83,7 +83,7 @@ where pub(crate) token_type_hint: Option>, pub(crate) auth_type: &'a AuthType, pub(crate) client_id: &'a ClientId, - pub(crate) client_secret: Option<&'a ClientSecret>, + pub(crate) client_secret: Option>, pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>, pub(crate) introspection_url: &'a IntrospectionUrl, pub(crate) _phantom: PhantomData<(TE, TIR)>, @@ -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 @@ -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, diff --git a/src/revocation.rs b/src/revocation.rs index 33f2df3..78ec8b4 100644 --- a/src/revocation.rs +++ b/src/revocation.rs @@ -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, @@ -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>, pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>, pub(crate) revocation_url: &'a RevocationUrl, pub(crate) _phantom: PhantomData<(RT, TE)>, @@ -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(self) -> Result> where RE: Error + 'static, @@ -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, diff --git a/src/token/mod.rs b/src/token/mod.rs index 97f8aac..6f51b6a 100644 --- a/src/token/mod.rs +++ b/src/token/mod.rs @@ -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, @@ -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, @@ -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(), @@ -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(), @@ -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>, pub(crate) code: AuthorizationCode, pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>, pub(crate) pkce_verifier: Option, @@ -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(self) -> Result> where RE: Error + 'static, @@ -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, @@ -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>, pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>, pub(crate) refresh_token: &'a RefreshToken, pub(crate) scopes: Vec>, @@ -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( self, @@ -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), @@ -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>, pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>, pub(crate) username: &'a ResourceOwnerUsername, pub(crate) password: &'a ResourceOwnerPassword, @@ -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( self, @@ -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), @@ -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>, pub(crate) extra_params: Vec<(Cow<'a, str>, Cow<'a, str>)>, pub(crate) scopes: Vec>, pub(crate) token_url: &'a TokenUrl, @@ -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( self, @@ -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),