### Error::description Method (Deprecated) Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.AuthorizationError.html Deprecated method for getting an error description. Prefer using the Display implementation or to_string() for error messages. ```rust fn description(&self) -> &str ``` -------------------------------- ### Implement From<&Credentials> for Client Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Creates a `Client` from a reference to `Credentials`. This is useful for quickly setting up a client with existing credentials. ```rust 44impl From<&Credentials> for Client { 45 fn from(value: &Credentials) -> Self { 46 Self::from(value.clone()) 47 } 48} ``` -------------------------------- ### Any::type_id Method Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.AuthorizationError.html Gets the TypeId of the current type. This is a blanket implementation provided by the Any trait. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Implement Client::new Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Provides a simple way to create a new `Client` instance with default settings (no credentials). ```rust 60impl Client { 61 pub fn new() -> Self { 62 Self::default() 63 } 64} ``` -------------------------------- ### Implement From> for Client Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Initializes a `Client` with OAuth credentials. This implementation uses `reqwest::Client::new()` as the inner client. ```rust 50impl>> From> for Client { 51 fn from(value: Credentials) -> Self { 52 Self { 53 inner: reqwest::Client::new(), 54 credentials: Some(value.into()), 55 } 56 } 57} ``` -------------------------------- ### Implement Client::with_credentials Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Creates a new `Client` instance and sets its OAuth credentials. This is a builder-style method for convenient initialization. ```rust 83 pub fn with_credentials> + fmt::Debug>( 84 mut self, 85 credentials: impl Into>>, 86 ) -> Self { 87 self.set_credentials_from(credentials.into()); 88 self 89 } ``` -------------------------------- ### PolicyExt::or Method Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.AuthorizationError.html Creates a new Policy that returns Action::Follow if either self or other policies return Action::Follow. ```rust fn or(self, other: P) -> Or where T: Policy, P: Policy ``` -------------------------------- ### Client Struct and Initialization Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Details on the Client struct, its fields, and methods for initialization and credential management. ```APIDOC ## Client Struct ### Description Represents an HTTP client that can be configured with optional OAuth1.0a credentials to authorize outgoing requests. ### Fields - `inner` (T): The underlying HTTP client (e.g., `reqwest::Client`). - `credentials` (Option): The OAuth1.0a credentials to use for authorization. ### Methods #### `new()` - **Description**: Creates a new `Client` with default settings and no credentials. - **Signature**: `pub fn new() -> Self` #### `set_credentials()` - **Description**: Sets or updates the `credentials` for the client. - **Parameters**: - `credentials` (Option): The credentials to set, or `None` to remove credentials. - **Signature**: `pub fn set_credentials(&mut self, credentials: Option)` #### `set_credentials_from()` - **Description**: Sets credentials from a type that can be converted into `Credentials`. - **Parameters**: - `credentials` (Option>): The credentials to set. - **Signature**: `fn set_credentials_from> + fmt::Debug>(&mut self, credentials: Option>)` #### `with_credentials()` - **Description**: Creates a new `Client` instance with the provided credentials. - **Parameters**: - `credentials` (impl Into>>): The credentials to associate with the client. - **Returns**: A new `Client` instance with the specified credentials. - **Signature**: `pub fn with_credentials> + fmt::Debug>(mut self, credentials: impl Into>>) -> Self` #### `credentials()` - **Description**: Returns the currently configured credentials. - **Returns**: An `Option>` representing the credentials, or `None` if not set. - **Signature**: `pub fn credentials(&self) -> Option>` #### `inner()` - **Description**: Returns a reference to the inner HTTP client. - **Returns**: A shared reference to the inner client (`&T`). - **Signature**: `pub fn inner(&self) -> &T` ### Implementations - `From` for `Client` - `From<&Credentials>` for `Client` - `From>` for `Client` ``` -------------------------------- ### Implement Client::set_credentials_from Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Internal helper to set credentials, converting them into the expected format. Used when initializing the client with credentials. ```rust 74 #[cfg_attr(feature = "tracing", tracing::instrument)] 75 fn set_credentials_from> + fmt::Debug>( 76 &mut self, 77 credentials: Option>, 78 ) { 79 self.credentials = credentials.map(Credentials::into); 80 } ``` -------------------------------- ### Implement From for Client Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Allows creating a `Client` from any type `T` that can be used as an inner HTTP client. The client will be initialized without credentials. ```rust 35impl From for Client { 36 fn from(value: T) -> Self { 37 Self { 38 inner: value, 39 credentials: None, 40 } 41 } 42} ``` -------------------------------- ### Basic Credentials Constructor Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Creates a `Credentials::Basic` variant. Use `basic_from` for convenience when the username or password types need conversion. ```rust pub fn basic(username: T, password: Option) -> Self { Self::Basic { username, password } } ``` ```rust pub fn basic_from>(username: impl Into, password: Option

) -> Self { Self::basic(username.into(), password.map(Into::into)) } ``` -------------------------------- ### PolicyExt::and Method Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.AuthorizationError.html Creates a new Policy that returns Action::Follow only if both self and other policies return Action::Follow. ```rust fn and(self, other: P) -> And where T: Policy, P: Policy ``` -------------------------------- ### Signer Initialization Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/struct.Signer.html Creates a new instance of the Signer struct using token, secret, consumer key, and consumer secret. ```APIDOC ## Signer::new ### Description Returns a new Signer instance for OAuth 1.0a signing. ### Parameters - **token** (&str) - Required - The OAuth token. - **secret** (&str) - Required - The OAuth secret. - **consumer_key** (&str) - Required - The consumer key. - **consumer_secret** (&str) - Required - The consumer secret. ### Response - **Result>** - Returns the Signer instance or a SignError if the system clock is invalid. ``` -------------------------------- ### Implement Credentials Builder Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Utility for constructing credentials with optional consumer data and conversion logic. ```rust pub type CredentialsBuilder> = Credentials>; impl CredentialsBuilder { pub fn with_consumer( self, default_consumer_key: impl Into, default_consumer_secret: impl Into, ) -> Credentials { match self { Self::Bearer { token } => Credentials::Bearer { token }, Self::Basic { username, password } => Credentials::Basic { username, password }, Self::OAuth1 { token, secret, consumer_key, consumer_secret, } => Credentials::OAuth1 { token, secret, consumer_key: consumer_key.unwrap_or_else(|| default_consumer_key.into()), consumer_secret: consumer_secret.unwrap_or_else(|| default_consumer_secret.into()), }, } } pub fn build(self) -> Result, CredentialsError> { self.try_into() } } ``` -------------------------------- ### Credentials Creation Methods Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Methods for creating instances of the `Credentials` enum. ```APIDOC ## Credentials Creation Methods ### Description Provides static methods to conveniently create `Credentials` instances. ### Methods - **`bearer(token: T) -> Self`**: Creates `Credentials::Bearer`. - **`bearer_from(token: impl Into) -> Self`**: Creates `Credentials::Bearer` from any type that can be converted into `T`. - **`basic(username: T, password: Option) -> Self`**: Creates `Credentials::Basic`. - **`basic_from>(username: impl Into, password: Option

) -> Self`**: Creates `Credentials::Basic` from types that can be converted into `T`. - **`oauth1(token: T, secret: T, consumer_key: U, consumer_secret: U) -> Self`**: Creates `Credentials::OAuth1`. - **`oauth1_from(...) -> Self`**: Creates `Credentials::OAuth1` from types that can be converted into `T` or `U`. ``` -------------------------------- ### Policy And Implementation Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/struct.Signer.html Creates a new `Policy` that returns `Action::Follow` only if both `self` and `other` policies return `Action::Follow`. ```rust fn and(self, other: P) -> And where T: Policy, P: Policy, ``` -------------------------------- ### Policy Or Implementation Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/struct.Signer.html Creates a new `Policy` that returns `Action::Follow` if either `self` or `other` policies return `Action::Follow`. ```rust fn or(self, other: P) -> Or where T: Policy, P: Policy, ``` -------------------------------- ### Implement Client::credentials Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Retrieves the currently configured OAuth credentials for the client. Returns an `Option` containing credentials as string slices. ```rust 91 /// Returns the credentials that will be used by this client to authorized 92 /// subsequent HTTP requests. 93 #[cfg_attr(feature = "tracing", tracing::instrument)] 94 pub fn credentials(&self) -> Option> { 95 self.credentials.as_ref().map(Credentials::as_ref) 96 } ``` -------------------------------- ### Create New Signer Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/struct.Signer.html Initializes a new Signer instance. Ensure the system's clock has not gone backward to avoid errors. ```rust pub fn new( token: &'a str, secret: &'a str, consumer_key: &'a str, consumer_secret: &'a str, ) -> Result> ``` -------------------------------- ### Credentials Module Overview Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/index.html Overview of the credentials module used to authorize HTTP requests in the oauth10a crate. ```APIDOC ## Credentials Module ### Description The credentials module provides the core structures required to authorize HTTP requests using the OAuth 1.0a protocol. ### Enums - **AuthorizationError**: Represents errors that occur during the authorization process. - **Credentials**: The primary structure used to authorize an HTTP request. - **CredentialsError**: Represents errors related to credential validation or usage. - **CredentialsKind**: Defines the type or category of the credentials. ### Type Aliases - **CredentialsBuilder**: A utility type used for constructing credentials with optional consumer key and secret. ``` -------------------------------- ### Implement ExecuteRequest for Client Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Enables the `Client` to execute HTTP requests, automatically authorizing them with credentials before sending. Handles `ClientError` for potential issues. ```rust 123impl ExecuteRequest for Client { 124 type Error = ClientError; 125 126 fn execute_request( 127 &self, 128 mut request: Request, 129 ) -> impl Future> + Send + 'static { 130 let result = self 131 .authorize(&mut request) 132 .map(|_| self.inner.execute_request(request)); 133 134 async move { result?.await.map_err(ClientError::Execute) } 135 } 136} ``` -------------------------------- ### Implement Drop for Client (with zeroize) Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Securely clears sensitive credential data from memory when the `Client` is dropped, provided the `zeroize` feature is enabled. This prevents credentials from lingering in memory. ```rust 137#[cfg(feature = "zeroize")] 138impl Drop for Client { 139 fn drop(&mut self) { 140 use zeroize::Zeroize; 141 142 if let Some(mut credentials) = self.credentials.take() { 143 credentials.zeroize(); 144 } 145 } 146} ``` -------------------------------- ### Generate Basic Authorization Header Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Constructs a Basic authentication header using username and an optional password. The input string is base64 encoded. ```rust let input = if let Some(password) = password { format!("{username}:{password}") } else { format!("{username}:") }; format!("Basic {}", BASE64_ENGINE.encode(input.as_bytes())) ``` -------------------------------- ### OAuth1 Credentials Constructor Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Creates a `Credentials::OAuth1` variant. Use `oauth1_from` for convenience when the token, secret, or consumer key types need conversion. ```rust pub fn oauth1(token: T, secret: T, consumer_key: U, consumer_secret: U) -> Self { Self::OAuth1 { token, secret, consumer_key, consumer_secret, } } ``` ```rust pub fn oauth1_from( token: impl Into, secret: impl Into, consumer_key: impl Into, consumer_secret: impl Into, ) -> Self { Self::oauth1( token.into(), secret.into(), consumer_key.into(), consumer_secret.into(), ) } ``` -------------------------------- ### Credentials as Reference Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Provides a `Credentials<&str>` reference to the existing credentials. This is useful for methods that require string slices without taking ownership. ```rust pub const fn as_ref(&self) -> Credentials<&str> { match self { Self::Bearer { token } => Credentials::Bearer { token }, Self::Basic { username, password } => Credentials::Basic { username, password: match password { None => None, Some(password) => Some(password), }, }, Self::OAuth1 { token, secret, consumer_key, consumer_secret, } => Credentials::OAuth1 { token, secret, consumer_key, consumer_secret, }, } } ``` -------------------------------- ### Authorization Header Construction Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Demonstrates the construction of different authorization header types based on provided credentials. ```APIDOC ## Authorization Header Construction This section outlines the different methods for constructing authorization headers. ### Supported Types - **Bearer**: Uses a token for authentication. - **Basic**: Uses username and password, encoded in Base64. - **OAuth1**: Uses token, secret, consumer key, and consumer secret for signing requests. ### Example Usage (Conceptual) ```rust // Assuming `method` and `endpoint` are defined match self { Self::Bearer { token } => format!("Bearer {token}"), Self::Basic { username, password } => { let input = if let Some(password) = password { format!("{username}:{password}") } else { format!("{username}:") }; format!("Basic {}", BASE64_ENGINE.encode(input.as_bytes())) } Self::OAuth1 { token, secret, consumer_key, consumer_secret } => { // This part involves signing the request, details depend on the Signer implementation // Signer::::new(token, secret, consumer_key, consumer_secret)?.sign(method, endpoint)?; String::from("OAuth1 signature placeholder") // Placeholder for actual signing logic } } ``` ``` -------------------------------- ### Client Struct Source: https://docs.rs/oauth10a/3.0.0/oauth10a/client/index.html Documentation for the Client struct used for HTTP operations. ```APIDOC ## Struct: Client ### Description HTTP client with optional `Credentials`. ### Usage Used to manage authentication and perform HTTP requests within the oauth10a framework. ``` -------------------------------- ### Error::provide Method (Nightly-only) Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.AuthorizationError.html Nightly-only experimental API for providing type-based access to error context, intended for error reporting tools. ```rust fn provide<'a>(&'a self, request: &mut Request<'a>) ``` -------------------------------- ### Define OAUTH1_VERSION_1 constant Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/constant.OAUTH1_VERSION_1.html Represents the OAuth 1.0 version string constant. ```rust pub const OAUTH1_VERSION_1: &str = "1.0"; ``` -------------------------------- ### Define Client Struct Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Represents an HTTP client that can optionally include OAuth credentials for automatic request authorization. Initialize with default settings or provide specific credentials. ```rust 29#[derive(Debug, Default, Clone)] 30#[must_use] 31pub struct Client { 32 inner: T, 33 credentials: Option, 34} ``` -------------------------------- ### Implement Client::inner Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Provides access to the underlying HTTP client instance. Use this for advanced configurations or direct operations on the inner client. ```rust 98 /// Returns a shared reference to the inner HTTP client. 99 #[cfg_attr(feature = "tracing", tracing::instrument)] 100 pub fn inner(&self) -> &T { 101 &self.inner 102 } ``` -------------------------------- ### Implement VZip for T Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.AuthorizationError.html This implementation provides a `vzip` method for types that implement `MultiLane`. ```rust impl VZip for T where V: MultiLane, Source§ ``` -------------------------------- ### Credentials Methods Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.Credentials.html Provides methods for building, transforming, and inspecting credentials. ```APIDOC ## Credentials Methods ### `with_consumer(self, default_consumer_key: impl Into, default_consumer_secret: impl Into) -> Credentials` Builds the credentials, filling missing consumer data with the provided default values. ### `build(self) -> Result, CredentialsError>` Builds the credentials. Returns an error if `consumer_key` or `consumer_secret` is missing for OAuth1 credentials. ### `kind(&self) -> CredentialsKind` Returns the kind of credentials. ### `bearer(token: T) -> Self` Creates Bearer credentials. ### `bearer_from(token: impl Into) -> Self` Creates Bearer credentials from a token. ### `basic(username: T, password: Option) -> Self` Creates Basic credentials. ### `basic_from>(username: impl Into, password: Option

) -> Self` Creates Basic credentials from username and optional password. ### `oauth1(token: T, secret: T, consumer_key: U, consumer_secret: U) -> Self` Creates OAuth1 credentials. ### `oauth1_from(token: impl Into, secret: impl Into, consumer_key: impl Into, consumer_secret: impl Into) -> Self` Creates OAuth1 credentials from token, secret, consumer key, and consumer secret. ### `from(credentials: Credentials) -> Self` where T: From Converts credentials from another type. ### `into(self) -> Credentials` where T: Into Converts credentials into another type. ### `as_ref(&self) -> Credentials<&str>` Returns a reference to the credentials as string slices. ### `authorization(self, method: &Method, endpoint: &Url) -> Result` Returns the value for the `Authorization` header. Currently, only `HMAC-SHA512` signature method is supported. Returns an error upon failure to produce the header value. ### `authorize(&self, request: &mut Request) -> Result` Appends an `Authorization` header to the `request`, unless it is already set. Returns `true` if the `Authorization` header was inserted. Returns an error upon failure to produce the header value. ``` -------------------------------- ### ExecuteRequest Implementation Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Details on how the Client implements the `ExecuteRequest` trait for executing HTTP requests. ```APIDOC ## ExecuteRequest Implementation for Client ### Description This section details how the `Client` struct implements the `ExecuteRequest` trait, enabling it to execute HTTP requests after applying authorization. ### Trait `ExecuteRequest` ### Associated Types - `Error`: The error type for request execution, aliased as `ClientError`. ### Method `execute_request()` ### Description Executes an HTTP request. It first attempts to authorize the request using the client's credentials and then delegates the execution to the inner HTTP client. ### Parameters - **request** (`Request`): The `reqwest::Request` to be executed. ### Returns - `impl Future> + Send + 'static`: A future that resolves to a `Result` containing either the `Response` or a `ClientError`. ### Error Handling - `ClientError::Authorize`: If the `authorize` method fails. - `ClientError::Execute`: If the underlying inner client fails to execute the request. ### Usage Example ```rust // Assuming 'client' is an instance of Client and 'request' is a reqwest::Request let response_future = client.execute_request(request); // To get the result: // let result = response_future.await; ``` ``` -------------------------------- ### Implement Credentials Conversion Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Conversion traits for transforming between Credentials and CredentialsBuilder. ```rust impl> From> for CredentialsBuilder { fn from(value: Credentials) -> Self { match value.into() { Credentials::Bearer { token } => Self::Bearer { token }, Credentials::Basic { username, password } => Self::Basic { username, password }, Credentials::OAuth1 { token, secret, consumer_key, consumer_secret, } => Self::OAuth1 { token, secret, consumer_key: Some(consumer_key), consumer_secret: Some(consumer_secret), }, } } } impl> TryFrom> for Credentials { type Error = CredentialsError; fn try_from(value: CredentialsBuilder) -> Result { Ok(match value { Credentials::Bearer { token } => Credentials::Bearer { token: token.into(), }, Credentials::Basic { username, password } => Credentials::Basic { username: username.into(), password: password.map(Into::into), }, Credentials::OAuth1 { token, secret, consumer_key, consumer_secret, } => Credentials::OAuth1 { token: token.into(), secret: secret.into(), consumer_key: consumer_key .ok_or(CredentialsError::MissingConsumerKey)? .into(), consumer_secret: consumer_secret .ok_or(CredentialsError::MissingConsumerSecret)? .into(), }, }) } } ``` -------------------------------- ### Implement Client::set_credentials Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Sets or updates the OAuth credentials for the client. This method replaces any existing credentials. ```rust 66 /// Sets the `credentials` to be used by the client to authorize HTTP request, 67 /// discarding the current value, if any. 68 #[cfg_attr(feature = "tracing", tracing::instrument)] 69 pub fn set_credentials(&mut self, credentials: Option) { 70 self.credentials = credentials; 71 } ``` -------------------------------- ### Define Credentials Error Types Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Error variants for missing consumer credentials during the build process. ```rust #[derive(Debug, thiserror::Error)] pub enum CredentialsError { #[error("missing consumer key")] MissingConsumerKey, #[error("missing consumer secret")] MissingConsumerSecret, } ``` -------------------------------- ### Define Credentials Kind Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Enum representing the supported authentication methods. ```rust #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum CredentialsKind { Bearer, Basic, OAuth1, } ``` -------------------------------- ### Credentials Methods Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/type.CredentialsBuilder.html Methods for the generic Credentials struct, including constructors for different credential types. ```APIDOC ## Methods for Credentials ### `kind` #### Description Returns the kind of credentials (e.g., Bearer, Basic, OAuth1). #### Signature `pub const fn kind(&self) -> CredentialsKind` ### `bearer` #### Description Creates a `Credentials` instance of type Bearer. #### Signature `pub const fn bearer(token: T) -> Self` ### `bearer_from` #### Description Creates a `Credentials` instance of type Bearer, accepting any type that can be converted into `T`. #### Signature `pub fn bearer_from(token: impl Into) -> Self` ### `basic` #### Description Creates a `Credentials` instance of type Basic. #### Signature `pub fn basic(username: T, password: Option) -> Self` ### `basic_from` #### Description Creates a `Credentials` instance of type Basic, accepting types that can be converted into `T` for username and `P` for password. #### Signature `pub fn basic_from>(username: impl Into, password: Option

) -> Self` ### `oauth1` #### Description Creates a `Credentials` instance of type OAuth1. #### Signature `pub fn oauth1(token: T, secret: T, consumer_key: U, consumer_secret: U) -> Self` ### `oauth1_from` #### Description Creates a `Credentials` instance of type OAuth1, accepting types that can be converted into `T` and `U`. #### Signature `pub fn oauth1_from(token: impl Into, secret: impl Into, consumer_key: impl Into, consumer_secret: impl Into) -> Self` ``` -------------------------------- ### Credentials Methods Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/type.CredentialsBuilder.html Methods for the Credentials struct, including conversion and creation of credential types. ```APIDOC ## Methods for Credentials ### `from` #### Description Creates a new `Credentials` instance from another `Credentials` instance, performing type conversion if necessary. #### Signature `pub fn from(credentials: Credentials) -> Self where T: From` ### `into` #### Description Converts the current `Credentials` instance into another `Credentials` instance with a different type, consuming the original instance. #### Signature `pub fn into(self) -> Credentials where T: Into` ``` -------------------------------- ### OAuth 1.0a Signer Structure Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/signer.rs.html Core structure for managing OAuth 1.0a signing parameters and generating request signatures. ```rust pub const OAUTH1_CONSUMER_KEY: &str = "oauth_consumer_key"; pub const OAUTH1_NONCE: &str = "oauth_nonce"; pub const OAUTH1_SIGNATURE: &str = "oauth_signature"; pub const OAUTH1_SIGNATURE_METHOD: &str = "oauth_signature_method"; pub const OAUTH1_TIMESTAMP: &str = "oauth_timestamp"; pub const OAUTH1_VERSION: &str = "oauth_version"; pub const OAUTH1_VERSION_1: &str = "1.0"; pub const OAUTH1_TOKEN: &str = "oauth_token"; /// OAuth1.0a signer. #[derive(Debug)] pub struct Signer<'a, T> { nonce: String, timestamp: String, token: &'a str, secret: &'a str, consumer_key: &'a str, consumer_secret: &'a str, _marker: PhantomData, } impl<'a, T: SignatureMethod> Signer<'a, T> { /// Returns a new `Signer`. /// /// # Errors /// /// If system's clock went backwards. pub fn new( token: &'a str, secret: &'a str, consumer_key: &'a str, consumer_secret: &'a str, ) -> Result> { let nonce = Uuid::new_v4().to_string(); let timestamp = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH)? .as_secs() .to_string(); Ok(Self { nonce, timestamp, token, secret, consumer_key, consumer_secret, _marker: PhantomData, }) } /// Returns OAuth1.0a parameters without the signature. fn params(&self) -> BTreeMap<&str, &str> { let mut params = BTreeMap::new(); let _ = params.insert(OAUTH1_CONSUMER_KEY, self.consumer_key); let _ = params.insert(OAUTH1_NONCE, &self.nonce); let _ = params.insert(OAUTH1_SIGNATURE_METHOD, T::SIGNATURE_METHOD); let _ = params.insert(OAUTH1_TIMESTAMP, &self.timestamp); let _ = params.insert(OAUTH1_TOKEN, self.token); let _ = params.insert(OAUTH1_VERSION, OAUTH1_VERSION_1); params } fn signature(&self, method: &Method, endpoint: &Url) -> String { let mut params = self.params(); let pairs = endpoint.query_pairs().collect::>(); params.extend(pairs.iter().map(|(k, v)| (k.as_ref(), v.as_ref()))); let mut params = params .into_iter() .map(|(k, v)| format!("{k}={}", urlencoding::encode(v))) .collect::>(); params.sort(); let base_url = format!( "{}{}", endpoint.origin().unicode_serialization(), endpoint.path() ); format!( "{}&{}&{}", urlencoding::encode(method.as_str()), urlencoding::encode(&base_url), urlencoding::encode(¶ms.join("&")) ) } fn signing_key(&self) -> String { format!( "{}&{}", urlencoding::encode(self.consumer_secret), ``` -------------------------------- ### Bearer Credentials Constructor Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Creates a `Credentials::Bearer` variant. Use `bearer_from` for convenience when the token type needs conversion. ```rust pub const fn bearer(token: T) -> Self { Self::Bearer { token } } ``` ```rust pub fn bearer_from(token: impl Into) -> Self { Self::bearer(token.into()) } ``` -------------------------------- ### sign Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/signer.rs.html Generates the formatted OAuth 1.0a Authorization header string by signing the request method and endpoint. ```APIDOC ## sign ### Description Returns the formatted value for the Authorization header by calculating the signature based on the provided method and endpoint. ### Method Internal Method ### Parameters - **method** (&Method) - Required - The HTTP method of the request. - **endpoint** (&Url) - Required - The target URL endpoint. ### Response - **Result>** - Returns the formatted OAuth header string on success, or a SignError if the signature process fails. ``` -------------------------------- ### Trait Implementations Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.Credentials.html Details on implemented traits for the Credentials type. ```APIDOC ## Trait Implementations ### `Clone` for `Credentials` Allows cloning credentials. ### `Debug` for `Credentials` Allows debugging credentials. ### `PartialEq` for `Credentials` Allows comparing credentials for equality. ### `Eq` for `Credentials` Indicates that equality is reflexive, symmetric, and transitive. ### `Copy` for `Credentials` Allows copying credentials. ### `From<&Credentials> for Client` Converts from a `&Credentials` to a `Client`. ### `From> for Client` where T: Into> Converts from `Credentials` to a `Client`. ### `From> for CredentialsBuilder` where U: Into Converts from `Credentials` to a `CredentialsBuilder`. ### `TryFrom> for Credentials` where U: Into Attempts to convert from `CredentialsBuilder` to `Credentials`, returning a `CredentialsError` on failure. ``` -------------------------------- ### Implement From for SignError Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/enum.SignError.html Allows converting a SystemTimeError directly into a SignError for a given SignatureMethod. ```rust impl From for SignError ``` -------------------------------- ### Define OAUTH1_VERSION constant Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/constant.OAUTH1_VERSION.html Represents the constant string key "oauth_version" used in OAuth 1.0a signing processes. ```rust pub const OAUTH1_VERSION: &str = "oauth_version"; ``` -------------------------------- ### ExecuteRequest::execute_request Source: https://docs.rs/oauth10a/3.0.0/oauth10a/execute/trait.ExecuteRequest.html Executes an HTTP request using the provided client implementation. ```APIDOC ## execute_request ### Description Executes the provided HTTP request and returns a future that resolves to a response or an error. ### Method N/A (Trait Method) ### Parameters #### Request Body - **request** (Request) - Required - The HTTP request object to be executed. ### Response #### Success Response - **Response** (Response) - The HTTP response returned by the server. #### Errors - **Error** (Self::Error) - Returned if the client fails to send the request. ``` -------------------------------- ### Implement WithSubscriber for T Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.AuthorizationError.html This implementation allows attaching subscribers to a type. ```rust impl WithSubscriber for T Source§ ``` -------------------------------- ### Define OAUTH1_TOKEN constant Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/constant.OAUTH1_TOKEN.html Represents the standard key for the OAuth token parameter. ```rust pub const OAUTH1_TOKEN: &str = "oauth_token"; ``` -------------------------------- ### CredentialsBuilder Implementation Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Provides methods for building and finalizing credentials, including handling default values and error checking. ```APIDOC ## CredentialsBuilder Implementation ### Methods #### `with_consumer` ```rust pub fn with_consumer( self, default_consumer_key: impl Into, default_consumer_secret: impl Into, ) -> Credentials ``` Builds the credentials, filling missing consumer data with the provided default values. This method is particularly useful when the `CredentialsBuilder` has optional consumer key and secret fields, and you want to ensure they are present in the final `Credentials` struct by providing defaults. #### `build` ```rust pub fn build(self) -> Result, CredentialsError> ``` Builds the credentials. This method attempts to convert the `CredentialsBuilder` into a `Credentials` struct. It returns an error (`CredentialsError`) if required fields like `consumer_key` or `consumer_secret` are missing and were not provided during the build process. ### Conversions #### `From> for CredentialsBuilder` Converts an existing `Credentials` struct into a `CredentialsBuilder`. This is useful for taking already constructed credentials and potentially modifying them using the builder pattern, especially for adding default consumer keys/secrets. #### `TryFrom> for Credentials` Attempts to convert a `CredentialsBuilder` into a `Credentials` struct. This conversion can fail with a `CredentialsError` if the builder is missing required consumer key or secret information. ``` -------------------------------- ### With Subscriber Implementation Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/struct.Signer.html Attaches a `Subscriber` to the type, returning a `WithDispatch` wrapper. The subscriber can be any type that can be converted into a `Dispatch`. ```rust fn with_subscriber(self, subscriber: S) -> WithDispatch where S: Into, ``` -------------------------------- ### Implement Client::authorize Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/client.rs.html Appends an `Authorization` header to a request if the client has credentials and the header is not already present. Returns `true` if the header was added. ```rust 113 #[cfg_attr(feature = "tracing", tracing::instrument)] 114 pub fn authorize(&self, request: &mut Request) -> Result { 115 match self.credentials() { 116 None => Ok(false), 117 Some(credentials) => credentials.authorize(request), 118 } 119 } ``` -------------------------------- ### From::from Method Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.AuthorizationError.html Returns the argument unchanged. This is a blanket implementation of the From trait. ```rust fn from(t: T) -> T ``` -------------------------------- ### Define OAUTH1_CONSUMER_KEY constant Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/constant.OAUTH1_CONSUMER_KEY.html Represents the standard OAuth 1.0a consumer key parameter name. ```rust pub const OAUTH1_CONSUMER_KEY: &str = "oauth_consumer_key"; ``` -------------------------------- ### Trait Implementations for Credentials Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/type.CredentialsBuilder.html Implementations of common Rust traits for the Credentials and CredentialsBuilder types. ```APIDOC ## Trait Implementations ### `From> for CredentialsBuilder` #### Description Converts a `Credentials` instance into a `CredentialsBuilder` instance. #### Signature `fn from(value: Credentials) -> Self` ### `Clone` for `Credentials` #### Description Provides the ability to clone `Credentials` instances. #### Methods - `clone(&self) -> Credentials`: Returns a duplicate of the value. - `clone_from(&mut self, source: &Self)`: Performs copy-assignment from `source`. ### `Debug` for `Credentials` #### Description Provides debugging output for `Credentials` instances. #### Methods - `fmt(&self, f: &mut Formatter<'_>) -> Result`: Formats the value using the given formatter. ### `PartialEq` for `Credentials` #### Description Provides equality comparison for `Credentials` instances. #### Methods - `eq(&self, other: &Credentials) -> bool`: Tests for `self` and `other` values to be equal. - `ne(&self, other: &Rhs) -> bool`: Tests for inequality. ### `TryFrom>> for Credentials` #### Description Attempts to convert a `CredentialsBuilder` into a `Credentials` instance. #### Associated Types - `Error`: `CredentialsError` #### Methods - `try_from(value: CredentialsBuilder) -> Result`: Performs the conversion. ### `Copy` for `Credentials` #### Description Indicates that `Credentials` instances can be copied. ### `Eq` for `Credentials` #### Description Indicates that `Credentials` instances support total equality comparison. ``` -------------------------------- ### With Current Subscriber Implementation Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/struct.Signer.html Attaches the current default `Subscriber` to the type, returning a `WithDispatch` wrapper. ```rust fn with_current_subscriber(self) -> WithDispatch ``` -------------------------------- ### Credentials Struct Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Represents the authentication credentials used for making HTTP requests. ```APIDOC ## Credentials Struct ### Description Represents the authentication credentials used to authorize an HTTP request. It can hold different types of credentials, such as Bearer tokens, Basic authentication, or OAuth 1.0a tokens and keys. ### Fields (The specific fields depend on the `CredentialsKind` and the generic type `T`, but typically include token, secret, username, password, consumer_key, and consumer_secret.) ### Derives - `Clone`, `Copy`, `PartialEq`, `Eq` for value semantics. - `serde::Serialize`, `serde::Deserialize` if the `serde` feature is enabled, allowing for serialization and deserialization. - `serde(untagged)` if `serde` is enabled, indicating that the serialization format should not include a type tag. ``` -------------------------------- ### OAUTH1_VERSION Constant Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/constant.OAUTH1_VERSION.html Defines the constant representing the OAuth version parameter key. ```APIDOC ## Constant OAUTH1_VERSION ### Description A constant string representing the key used for the OAuth version parameter in requests. ### Value "oauth_version" ``` -------------------------------- ### VZip Implementation Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/struct.Signer.html Implements the `vzip` method for types that support multi-lane operations, returning a V type. ```rust fn vzip(self) -> V ``` -------------------------------- ### CredentialsBuilder Methods Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/type.CredentialsBuilder.html Methods available for building and manipulating credentials using the CredentialsBuilder. ```APIDOC ## Methods for CredentialsBuilder ### `with_consumer` #### Description Builds the credentials, filling missing consumer data with the provided default values. #### Signature `pub fn with_consumer(self, default_consumer_key: impl Into, default_consumer_secret: impl Into) -> Credentials` ### `build` #### Description Builds the credentials. #### Signature `pub fn build(self) -> Result, CredentialsError>` #### Errors - If one of `consumer_key` and `consumer_secret` is missing. ``` -------------------------------- ### Credentials Conversion Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Methods for converting between different credential types and string slices. ```APIDOC ## Credentials Conversion ### Description Provides methods for converting credentials between types and for accessing them as string slices. ### Methods - **`from(credentials: Credentials) -> Self`**: Converts `Credentials` to `Credentials` where `T: From`. - **`into(self) -> Credentials`**: Converts `self` to `Credentials` where `T: Into`. - **`as_ref(&self) -> Credentials<&str>`**: Returns a reference to the credentials as string slices (`&str`). This is useful for operations that require string slices, like generating authorization headers. ``` -------------------------------- ### Sign HTTP requests for OAuth 1.0a Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/signer.rs.html Generates an Authorization header string by signing the request method and endpoint. Requires a valid signing key and signature digest implementation. ```rust pub fn sign(self, method: &Method, endpoint: &Url) -> Result> { let signing_key = self.signing_key(); let signature = self.signature(method, endpoint); let signature = T::digest(&signing_key, &signature).map_err(SignError::Digest)?; let signature = urlencoding::encode(&signature); let mut params = self.params(); let _ = params.insert(OAUTH1_SIGNATURE, &signature); let mut params = params .into_iter() .map(|(k, v)| format!("{k}=\"{v}\"")) .collect::>(); params.sort(); Ok(format!("OAuth {}", params.join(", "))) } ``` -------------------------------- ### ToString::to_string Method Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.AuthorizationError.html Converts the given value to a String. This is part of the standard ToString trait. ```rust fn to_string(&self) -> String ``` -------------------------------- ### Implement PolicyExt for T Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/enum.SignError.html Extends any type T with policy-related methods like 'and' and 'or'. Requires T to be a Policy and ?Sized. ```rust impl PolicyExt for T where T: ?Sized, ``` -------------------------------- ### Policy Composition Source: https://docs.rs/oauth10a/3.0.0/oauth10a/client/struct.Client.html Methods for combining policy objects using logical OR operations. ```APIDOC ## fn or(self, other: P) -> Or ### Description Creates a new Policy that returns Action::Follow if either self or other returns Action::Follow. ### Parameters #### Path Parameters - **other** (P) - Required - The secondary policy to evaluate. ``` -------------------------------- ### Define OAUTH1_SIGNATURE_METHOD constant Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/constant.OAUTH1_SIGNATURE_METHOD.html Represents the standard key string used for the OAuth 1.0a signature method parameter. ```rust pub const OAUTH1_SIGNATURE_METHOD: &str = "oauth_signature_method"; ``` -------------------------------- ### Subscriber Dispatching Source: https://docs.rs/oauth10a/3.0.0/oauth10a/client/struct.Client.html Methods for attaching subscribers to types for dispatching purposes. ```APIDOC ## fn with_subscriber(self, subscriber: S) -> WithDispatch ### Description Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. ### Parameters #### Path Parameters - **subscriber** (S) - Required - The subscriber to attach. ## fn with_current_subscriber(self) -> WithDispatch ### Description Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. ``` -------------------------------- ### Implement Same for T Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/enum.SignError.html Implements the Same trait for any type T, indicating that the output type is the same as the input type. ```rust impl Same for T ``` -------------------------------- ### VZip Trait Implementation Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.AuthorizationError.html Provides the vzip method for types implementing MultiLane. ```APIDOC ## fn vzip(self) -> V ### Description Zips the current type into a MultiLane structure. ### Parameters - **self** - Required - The instance to be zipped. ``` -------------------------------- ### WithSubscriber Trait Methods Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/enum.SignError.html Methods for attaching subscribers to types to enable tracing and dispatching. ```APIDOC ## fn with_subscriber(self, subscriber: S) -> WithDispatch ### Description Attaches the provided `Subscriber` to this type, returning a `WithDispatch` wrapper. ### Parameters #### Generic Parameters - **S** (Into) - Required - The subscriber to be attached. ## fn with_current_subscriber(self) -> WithDispatch ### Description Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper. ``` -------------------------------- ### Generate Authorization Header Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/struct.Signer.html Signs an HTTP request and returns the formatted Authorization header value. ```APIDOC ## Signer::sign ### Description Generates the formatted value for the Authorization header based on the provided HTTP method and endpoint URL. ### Parameters - **method** (&Method) - Required - The HTTP method of the request. - **endpoint** (&Url) - Required - The target URL of the request. ### Response - **Result>** - Returns the Authorization header string or a SignError if the signature generation fails. ``` -------------------------------- ### Credentials Kind Method Source: https://docs.rs/oauth10a/3.0.0/src/oauth10a/credentials.rs.html Returns the variant of the `Credentials` enum. This is a const function, meaning it can be evaluated at compile time. ```rust pub const fn kind(&self) -> CredentialsKind { match self { Self::Bearer { .. } => CredentialsKind::Bearer, Self::Basic { .. } => CredentialsKind::Basic, Self::OAuth1 { .. } => CredentialsKind::OAuth1, } } ``` -------------------------------- ### Into::into Method Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.AuthorizationError.html Calls U::from(self). This is a blanket implementation of the Into trait. ```rust fn into(self) -> U ``` -------------------------------- ### Client Authorization API Source: https://docs.rs/oauth10a/3.0.0/oauth10a/client/struct.Client.html Methods for managing credentials and authorizing HTTP requests using the oauth10a::Client. ```APIDOC ## Client::authorize ### Description Appends an `Authorization` header to the provided `Request` if the client has credentials and the header is not already set. ### Parameters - **request** (&mut Request) - Required - The HTTP request to be authorized. ### Response - **Result** - Returns `true` if the `Authorization` header was successfully inserted. Returns an error if the header value could not be produced. ## Client::set_credentials ### Description Sets the credentials to be used by the client for authorizing HTTP requests, discarding any existing credentials. ### Parameters - **credentials** (Option) - Required - The new credentials to set. ## Client::with_credentials ### Description Creates a new client instance with the specified credentials, discarding any existing ones. ### Parameters - **credentials** (impl Into>>) - Required - The credentials to initialize the client with. ### Response - **Client** - A new instance of the client with the provided credentials. ``` -------------------------------- ### VZip Function Source: https://docs.rs/oauth10a/3.0.0/oauth10a/credentials/enum.AuthorizationError.html The `vzip` function is part of the `VZip` implementation. ```rust fn vzip(self) -> V Source§ ``` -------------------------------- ### Implement ToString for T Source: https://docs.rs/oauth10a/3.0.0/oauth10a/signer/enum.SignError.html Implements the ToString trait for any type T that also implements Display. Allows conversion to a String. ```rust impl ToString for T where T: Display + ?Sized, ```