1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use Any;
use Result;
/// A storage provider. Implementors should pick a concrete `Request` type, representing a
/// struct or parameter sent by a corresponding [`Scheme`].
///
/// # Example
///
/// ```no_run
/// # use async_std::task::block_on;
/// # fn main() -> Result<(), std::io::Error> { block_on(async {
/// #
/// use tide_http_auth::{ Storage, BasicAuthRequest, BasicAuthScheme };
/// #[derive(Clone)]
/// 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<Option<MyUserType>> {
/// if request.username == "Basil" && request.password == "meow time now" {
/// // If the credential request succeeds, return your user type here.
/// Ok(Some(MyUserType{username: "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.with(tide_http_auth::Authentication::new(BasicAuthScheme::default()));
///
/// # Ok(()) })}
/// ```