pub struct RemoteUserAuthentication { /* private fields */ }Expand description
Remote user authentication backend
Authenticates users based on a trusted HTTP header (typically REMOTE_USER) set by an upstream authentication layer.
§Security Warning
This backend trusts the specified header completely. Only use this when your application is behind a properly configured authentication proxy that prevents clients from spoofing this header.
§Examples
use reinhardt_auth::{AuthenticationBackend, SimpleUser};
use bytes::Bytes;
use hyper::{HeaderMap, Method};
use reinhardt_http::Request;
// Create auth backend
let auth = reinhardt_auth::RemoteUserAuth::new();
// Create request with REMOTE_USER header
let mut headers = HeaderMap::new();
headers.insert("REMOTE_USER", "alice".parse().unwrap());
let request = Request::builder()
.method(Method::GET)
.uri("/")
.headers(headers)
.body(Bytes::new())
.build()
.unwrap();
let result = auth.authenticate(&request).await.unwrap();
assert!(result.is_some());
assert_eq!(result.unwrap().get_username(), "alice");Implementations§
Source§impl RemoteUserAuthentication
impl RemoteUserAuthentication
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new remote user authentication backend
§Examples
use reinhardt_auth::RemoteUserAuth;
let auth = RemoteUserAuth::new();Sourcepub fn with_header(self, header: impl Into<String>) -> Self
pub fn with_header(self, header: impl Into<String>) -> Self
Set custom header name
§Examples
use reinhardt_auth::RemoteUserAuth;
let auth = RemoteUserAuth::new()
.with_header("X-Auth-User");Sourcepub fn force_logout(self, force: bool) -> Self
pub fn force_logout(self, force: bool) -> Self
Set whether to force logout when header is missing
Trait Implementations§
Source§impl AuthenticationBackend for RemoteUserAuthentication
impl AuthenticationBackend for RemoteUserAuthentication
Source§fn authenticate<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 Request,
) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn User>>, AuthenticationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn authenticate<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 Request,
) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn User>>, AuthenticationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Authenticate a request and return a user if successful Read more
Auto Trait Implementations§
impl Freeze for RemoteUserAuthentication
impl RefUnwindSafe for RemoteUserAuthentication
impl Send for RemoteUserAuthentication
impl Sync for RemoteUserAuthentication
impl Unpin for RemoteUserAuthentication
impl UnsafeUnpin for RemoteUserAuthentication
impl UnwindSafe for RemoteUserAuthentication
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().