Trait AuthHandler

Source
pub trait AuthHandler<Data> {
    // Required method
    fn jwt_secret<F: FnOnce() -> Option<Data>>(
        &self,
        state: &mut State,
        decode_data: F,
    ) -> Option<Vec<u8>>;
}
Expand description

This trait will help the auth middleware to determine the validity of an authentication token.

A very basic implementation could look like this:

const SECRET: &'static [u8; 32] = b"zlBsA2QXnkmpe0QTh8uCvtAEa4j33YAc";

struct CustomAuthHandler;
impl<T> AuthHandler<T> for CustomAuthHandler {
	fn jwt_secret<F: FnOnce() -> Option<T>>(
		&self,
		_state: &mut State,
		_decode_data: F
	) -> Option<Vec<u8>> {
		Some(SECRET.to_vec())
	}
}

Required Methods§

Source

fn jwt_secret<F: FnOnce() -> Option<Data>>( &self, state: &mut State, decode_data: F, ) -> Option<Vec<u8>>

Return the SHA256-HMAC secret used to verify the JWT token.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§