Skip to main content

Module token

Module token 

Source
Expand description

Token-based authentication connection hooks.

This module provides ready-to-use connection hooks for simple token-based authentication:

  • ServerHook - Server-side connection hook that validates client tokens
  • ClientHook - Client-side connection hook that sends a token to the server

§Example

use bytes::Bytes;
use msg_socket::{
    RepSocket, ReqSocket,
    hooks::token::{ClientHook, ServerHook},
};
use msg_transport::tcp::Tcp;

// Server side - validates incoming tokens
let rep = RepSocket::new(Tcp::default()).with_connection_hook(ServerHook::new(|token| {
    // Custom validation logic
    **token == *b"secret"
}));

// Client side - sends token on connect
let req =
    ReqSocket::new(Tcp::default()).with_connection_hook(ClientHook::new(Bytes::from("secret")));

Structs§

ClientHook
Client-side authentication connection hook that sends a token to the server.
ServerHook
Server-side authentication connection hook that validates incoming client tokens.

Enums§

ClientHookError
Error type for client-side token authentication.
ServerHookError
Error type for server-side token authentication.