pub struct AuthenticatedConnection { /* private fields */ }Expand description
Authenticated WebSocket connection wrapper
§Examples
use reinhardt_websockets::auth::{AuthenticatedConnection, SimpleAuthUser};
use reinhardt_websockets::WebSocketConnection;
use tokio::sync::mpsc;
use std::sync::Arc;
let (tx, _rx) = mpsc::unbounded_channel();
let conn = Arc::new(WebSocketConnection::new("conn_1".to_string(), tx));
let user = SimpleAuthUser::new(
"user_1".to_string(),
"alice".to_string(),
vec!["chat.read".to_string()],
);
let auth_conn = AuthenticatedConnection::new(conn, Box::new(user));
assert_eq!(auth_conn.user().username(), "alice");Implementations§
Source§impl AuthenticatedConnection
impl AuthenticatedConnection
Sourcepub fn new(
connection: Arc<WebSocketConnection>,
user: Box<dyn AuthUser>,
) -> Self
pub fn new( connection: Arc<WebSocketConnection>, user: Box<dyn AuthUser>, ) -> Self
Create a new authenticated connection
Sourcepub fn connection(&self) -> &Arc<WebSocketConnection>
pub fn connection(&self) -> &Arc<WebSocketConnection>
Get the underlying WebSocket connection
Sourcepub async fn send_with_auth<P: AuthorizationPolicy>(
&self,
message: Message,
policy: &P,
) -> WebSocketResult<()>
pub async fn send_with_auth<P: AuthorizationPolicy>( &self, message: Message, policy: &P, ) -> WebSocketResult<()>
Send a message with authorization check
Auto Trait Implementations§
impl Freeze for AuthenticatedConnection
impl !RefUnwindSafe for AuthenticatedConnection
impl Send for AuthenticatedConnection
impl Sync for AuthenticatedConnection
impl Unpin for AuthenticatedConnection
impl UnsafeUnpin for AuthenticatedConnection
impl !UnwindSafe for AuthenticatedConnection
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