pub struct AuthConfig {
pub basic: Option<BasicCredential>,
pub authorizer: Authorizer,
/* private fields */
}Expand description
Which credentials the server accepts. An empty config (the default) means the server is open — no interceptor is installed.
Fields§
§basic: Option<BasicCredential>Accepted Basic username/password, if any.
Per-query authorization policy, consulted after a query resolves. The
default Authorizer::AllowAll is a no-op (no behavior change).
Implementations§
Source§impl AuthConfig
impl AuthConfig
Sourcepub fn with_bearer_token(self, token: impl Into<String>) -> Self
pub fn with_bearer_token(self, token: impl Into<String>) -> Self
A single accepted bearer token (back-compat shape). Equivalent to
with_bearer_tokens with one element; the token names itself.
Sourcepub fn with_bearer_tokens<I, S>(self, tokens: I) -> Self
pub fn with_bearer_tokens<I, S>(self, tokens: I) -> Self
A set of accepted bearer tokens for zero-downtime rotation. Any
listed token authenticates; the first is issued by the handshake. Each
token names itself as its Identity (use
with_named_bearer_tokens to map tokens to authz identities).
Sourcepub fn with_named_bearer_tokens<I, S1, S2>(self, tokens: I) -> Self
pub fn with_named_bearer_tokens<I, S1, S2>(self, tokens: I) -> Self
A set of accepted bearer tokens mapped to authz identity names, so
several tokens can share one identity (e.g. an old and a new token for
the same analyst role rotate transparently). Pairs are (token, identity_name); the first pair’s token is issued by the handshake.
Sourcepub fn add_bearer_token(&mut self, token: impl Into<String>) -> &mut Self
pub fn add_bearer_token(&mut self, token: impl Into<String>) -> &mut Self
Add one accepted bearer token (self-named). Keeps any already added —
the building block for rotation. Returns &mut Self for chaining.
Sourcepub fn add_named_bearer_token(
&mut self,
token: impl Into<String>,
name: impl Into<String>,
) -> &mut Self
pub fn add_named_bearer_token( &mut self, token: impl Into<String>, name: impl Into<String>, ) -> &mut Self
Add one accepted bearer token mapped to an authz identity name.
Sourcepub fn with_basic(
self,
username: impl Into<String>,
password: impl Into<String>,
) -> Self
pub fn with_basic( self, username: impl Into<String>, password: impl Into<String>, ) -> Self
Accept Basic username / password.
Attach a per-query Authorizer. Default is Authorizer::AllowAll.
Authorize an already-resolved query for an identity (delegates to the
configured Authorizer). Denial → permission_denied.
Sourcepub fn bearer_tokens(&self) -> impl Iterator<Item = &str>
pub fn bearer_tokens(&self) -> impl Iterator<Item = &str>
All accepted bearer token values, in insertion order.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Any credential method configured? When false, the server requires no authentication and the interceptor is skipped entirely.
Sourcepub fn issued_token(&self) -> Option<&str>
pub fn issued_token(&self) -> Option<&str>
The token issued to a client after a successful handshake — the first configured bearer token, which the client then replays on each call.
Sourcepub fn check_header(&self, header: Option<&str>) -> Result<(), Status>
pub fn check_header(&self, header: Option<&str>) -> Result<(), Status>
Validate an authorization header value against every configured
method. Open servers accept anything (including a missing header).
A thin wrapper over authenticate that discards
the resolved Identity; kept for call sites that only gate access.
Sourcepub fn authenticate(&self, header: Option<&str>) -> Result<Identity, Status>
pub fn authenticate(&self, header: Option<&str>) -> Result<Identity, Status>
Validate an authorization header and return the resolved Identity.
Open servers (no method configured) authenticate anything as
Identity::Anonymous. Otherwise a valid Bearer token resolves to its
mapped Identity::Token and valid Basic creds to Identity::Basic;
anything else is unauthenticated.
Sourcepub fn check_basic(&self, b64: &str) -> Option<String>
pub fn check_basic(&self, b64: &str) -> Option<String>
Validate a base64-encoded user:pass Basic payload, returning the
username on success.
Trait Implementations§
Source§impl Clone for AuthConfig
impl Clone for AuthConfig
Source§fn clone(&self) -> AuthConfig
fn clone(&self) -> AuthConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AuthConfig
impl Debug for AuthConfig
Source§impl Default for AuthConfig
impl Default for AuthConfig
Source§fn default() -> AuthConfig
fn default() -> AuthConfig
Auto Trait Implementations§
impl !RefUnwindSafe for AuthConfig
impl !UnwindSafe for AuthConfig
impl Freeze for AuthConfig
impl Send for AuthConfig
impl Sync for AuthConfig
impl Unpin for AuthConfig
impl UnsafeUnpin for AuthConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request