[−][src]Trait tide_http_auth::Storage
A storage provider. Implementors should pick a concrete Request
type, representing a
struct or parameter sent by a corresponding [Scheme
].
Example
use tide_http_auth::{ Storage, BasicAuthRequest, BasicAuthScheme }; struct MyState; struct MyUserType { username: String } let state = MyState { }; // note that we're implementing the concrete "BasicAuthRequest" type here. #[async_trait::async_trait] impl Storage<MyUserType, BasicAuthRequest> for MyState { async fn get_user(&self, request: BasicAuthRequest) -> tide::Result<MyUserType> { if request.username == "Basil" && request.password == "meow time now" { // If the credential request succeeds, return your user type here. Ok(Some(MyUserType("Basil".to_string()))) } else { Ok(None) // Nothing went wrong, but these credentials are invalid. // you might also return Err here, to indicate a problem talking to the backing store. } } } let mut app = tide::with_state(state); // BasicAuthScheme's ::Request associated type is BasicAuthRequest. app.middleware(tide_http_auth::Authentication::new(BasicAuthScheme::default()));