pub trait DittoAuthExpirationHandler:
'static
+ Send
+ Sync {
// Required method
fn on_expiration(
&self,
ditto: &Ditto,
duration_remaining: Duration,
) -> impl Send + Future<Output = ()>;
}Expand description
Trait describing types which can be used as an authentication expiration handler for Ditto.
When using DittoConfigConnect::Server { .. } mode, Ditto requires you to register an
“expiration handler” for authentication. This handler is called for an initial authentication
and periodically thereafter when the current authentication is near to expiration.
This trait is implemented for async closures and for functions returning an
impl Future<Output = ()>, which take the expected arguments of an auth expiration handler.
Expiration handlers are expected to call auth.login(...) with a valid authentication token.
For more details about authentication, see the Ditto Auth and Authorization docs.
NOTE: Because expiration handlers are asynchronous, they must not block the thread.
§Example
let auth = ditto
.auth()
.expect("Auth is available for DittoConfigConnect::Server mode");
// Option 1: Use an async closure
auth.set_expiration_handler(async |ditto: &Ditto, duration| {
// Your authentication handler code here
});
// Option 2: Use a closure returning an async block
auth.set_expiration_handler(|ditto: &Ditto, duration| async {
// Your authentication handler code here
});
// Option 3: Use a custom type and trait impl
struct MyAuthHandler;
impl DittoAuthExpirationHandler for MyAuthHandler {
async fn on_expiration(&self, ditto: &Ditto, duration_remaining: Duration) {
// Your authentication handler code here
}
}
auth.set_expiration_handler(MyAuthHandler);Required Methods§
fn on_expiration( &self, ditto: &Ditto, duration_remaining: Duration, ) -> impl Send + Future<Output = ()>
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.