pub struct OidcAuth { /* private fields */ }sso only.Expand description
OIDC / OAuth 2.0 authentication middleware.
See the module documentation for a usage example.
Implementations§
Source§impl OidcAuth
impl OidcAuth
Sourcepub fn new(config: OidcConfig, sessions: Arc<SessionStore>) -> OidcAuth
pub fn new(config: OidcConfig, sessions: Arc<SessionStore>) -> OidcAuth
Create a new OidcAuth middleware.
sessions is the session store shared with the application.
Sourcepub fn exclude(self, prefix: &str) -> OidcAuth
pub fn exclude(self, prefix: &str) -> OidcAuth
Exclude a path prefix from authentication checks.
Requests whose path starts with prefix bypass the session check and
are passed directly to the next layer. Use this for public paths like
/healthz or /public/.
Sourcepub fn login_path(self, path: &str) -> OidcAuth
pub fn login_path(self, path: &str) -> OidcAuth
Override the login redirect path (default: "/auth/login").
Sourcepub fn callback_path(self, path: &str) -> OidcAuth
pub fn callback_path(self, path: &str) -> OidcAuth
Override the callback path (default: "/auth/callback").
Sourcepub fn logout_path(self, path: &str) -> OidcAuth
pub fn logout_path(self, path: &str) -> OidcAuth
Override the logout path (default: "/auth/logout").
Keep sessions in an HMAC-SHA256-signed cookie (_rws_oidc) instead
of the SessionStore: nothing is held in memory, so sessions
survive a restart and every replica sharing secret accepts them.
Sourcepub fn session_ttl(self, secs: u64) -> OidcAuth
pub fn session_ttl(self, secs: u64) -> OidcAuth
How long a sign-in lasts (default 24 h).
Sourcepub fn allow_emails(
self,
emails: impl IntoIterator<Item = impl Into<String>>,
) -> OidcAuth
pub fn allow_emails( self, emails: impl IntoIterator<Item = impl Into<String>>, ) -> OidcAuth
Admit users with one of these (verified) email addresses.
Sourcepub fn allow_domains(
self,
domains: impl IntoIterator<Item = impl Into<String>>,
) -> OidcAuth
pub fn allow_domains( self, domains: impl IntoIterator<Item = impl Into<String>>, ) -> OidcAuth
Admit users whose (verified) email is in one of these domains.
Sourcepub fn allow_groups(
self,
claim: &str,
groups: impl IntoIterator<Item = impl Into<String>>,
) -> OidcAuth
pub fn allow_groups( self, claim: &str, groups: impl IntoIterator<Item = impl Into<String>>, ) -> OidcAuth
Admit users with one of these groups in the ID token’s claim
(groups by default; Keycloak, Okta, Azure AD and Authentik send one).
Sourcepub fn forward_headers(self, on: bool) -> OidcAuth
pub fn forward_headers(self, on: bool) -> OidcAuth
Send X-Auth-Request-User (sub), X-Auth-Request-Email and
X-Auth-Request-Groups to the next layer.
Sourcepub fn signed_in(&self, request: &Request) -> Option<SignedIn>
pub fn signed_in(&self, request: &Request) -> Option<SignedIn>
Who is signed in on request (a valid session cookie), without
redirecting: for callers that check identity themselves, like the
admin API (18.22.0). Allow-lists are not applied.
Sourcepub fn claims(req: &Request) -> Option<OidcClaims>
pub fn claims(req: &Request) -> Option<OidcClaims>
Read the OIDC claims injected by OidcAuth from a request.
Returns None if the request did not pass through an authenticated
OidcAuth layer.
Trait Implementations§
Source§impl Middleware for OidcAuth
impl Middleware for OidcAuth
fn handle( &self, request: &Request, connection: &ConnectionInfo, next: &dyn Application, ) -> Result<Response, String>
Source§fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
true when this layer’s own work for request never blocks (in-memory
state, atomics, short mutexes) — see Application::runs_inline. A
WithMiddleware stack runs inline only if every layer and the inner
application agree. Default false.Source§fn is_passthrough(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn is_passthrough( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when handle would do nothing for request but call next
(e.g. a rate limit that isn’t configured). A WithMiddleware stack
offers the inner application’s execute_async only if every layer
passes the request through. Default false.Source§fn accepts_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn accepts_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when this layer never reads request.body, so the inner
application may receive it as a stream (Application::streams_body).
A layer that inspects the body (CSRF tokens in a form, request
signatures, rewriting) must keep the default false: it would see an
empty body.Source§fn answers_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn answers_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when this layer answers request itself — it doesn’t call
next — and reads its body as a stream (a proxy forwarding it as it
arrives). The body is then streamed whatever the layers after it and
the application would say. Requires accepts_streamed_body. Since
18.3.0.Source§fn layer_name(&self) -> &'static str
fn layer_name(&self) -> &'static str
Application::middleware_names): by default the type’s name
without its module path or generic parameters (CacheLayer). Since
18.28.0.Auto Trait Implementations§
impl Freeze for OidcAuth
impl RefUnwindSafe for OidcAuth
impl Send for OidcAuth
impl Sync for OidcAuth
impl Unpin for OidcAuth
impl UnsafeUnpin for OidcAuth
impl UnwindSafe for OidcAuth
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> 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> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
map-response-body only.Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
trace only.