60 lines
1.7 KiB
Rust
60 lines
1.7 KiB
Rust
//! Authentication models shared across protocol connectors.
|
|
|
|
#![forbid(unsafe_code)]
|
|
|
|
use std::collections::HashMap;
|
|
|
|
/// Authentication scheme recognized by the protocol layer.
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub enum AuthScheme {
|
|
/// HTTP Basic authentication.
|
|
Basic,
|
|
/// HTTP Digest authentication.
|
|
Digest,
|
|
/// Bearer-token authentication.
|
|
Bearer,
|
|
/// SPNEGO or Negotiate authentication.
|
|
Negotiate,
|
|
/// NTLM authentication.
|
|
Ntlm,
|
|
/// OAuth2-derived bearer flows.
|
|
OAuth2,
|
|
/// Caller accepts any supported scheme.
|
|
Any,
|
|
}
|
|
|
|
/// Authentication material supplied to a protocol connector.
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct AuthCredentialModel {
|
|
/// Scheme the credential applies to.
|
|
pub scheme: AuthScheme,
|
|
/// Optional username component.
|
|
pub username: Option<String>,
|
|
/// Optional password or shared secret.
|
|
pub password: Option<String>,
|
|
/// Optional opaque bearer token.
|
|
pub token: Option<String>,
|
|
/// Optional authentication realm.
|
|
pub realm: Option<String>,
|
|
}
|
|
|
|
/// Authentication challenge emitted by a server.
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct AuthChallengeModel {
|
|
/// Challenged scheme.
|
|
pub scheme: AuthScheme,
|
|
/// Optional realm attached to the challenge.
|
|
pub realm: Option<String>,
|
|
/// Additional challenge parameters keyed by attribute name.
|
|
pub parameters: HashMap<String, String>,
|
|
}
|
|
|
|
/// Cached credential entry associated with an origin.
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct AuthCacheEntry {
|
|
/// Origin or protection-space key.
|
|
pub origin: String,
|
|
/// Credential cached for the origin.
|
|
pub credential: AuthCredentialModel,
|
|
}
|