pub enum Auth {
None,
Bearer {
token: String,
},
Basic {
username: String,
password: String,
},
ApiKey {
header: String,
value: String,
},
ApiKeyQuery {
param: String,
value: String,
},
OAuth2 {
token_url: String,
client_id: String,
client_secret: String,
scopes: Vec<String>,
expiry_ratio: f64,
},
TokenEndpoint {
url: String,
method: Method,
headers: HeaderMap,
body: Option<Value>,
token_path: String,
expiry_path: Option<String>,
expiry_ratio: f64,
response_validator: Option<ResponseValidator>,
},
Custom {
headers: HashMap<String, String>,
},
}Expand description
Supported authentication methods.
Variants§
None
Bearer
Bearer token in the Authorization header.
Basic
ApiKey
API key sent in a request header.
ApiKeyQuery
API key sent as a query parameter (e.g. ?api_key=secret).
Some APIs require the key in the URL rather than a header. The param
field is the query parameter name, and value is the key itself.
OAuth2
Fields
TokenEndpoint
Fetch a token from an arbitrary HTTP endpoint.
The endpoint is called, the token is extracted from the JSON response
using token_path (a JSONPath expression), and then used as a Bearer
token (or in a custom header if header_name is set).
Tokens are cached and refreshed automatically when expiry_path
is provided and the server returns an expiry value.
Fields
expiry_path: Option<String>Optional JSONPath expression to extract the expiry (in seconds) from the response. When absent, the token is cached indefinitely.
expiry_ratio: f64Fraction of the expiry after which the token is proactively refreshed.
Must be in (0.0, 1.0]. Defaults to 0.9.
response_validator: Option<ResponseValidator>Optional callback to decide whether the token endpoint response is
successful. Receives the HTTP status code. When None, defaults to
status.is_success() (2xx).
Custom
Arbitrary headers attached to every request (e.g. multi-tenant routing, API keys split across several headers).
Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Auth
impl<'de> Deserialize<'de> for Auth
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for Auth
impl JsonSchema for Auth
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more