Skip to main content

rustauth_plugins/one_time_token/
mod.rs

1//! One-time token plugin.
2
3mod endpoints;
4mod hashing;
5mod headers;
6mod options;
7
8pub use hashing::default_key_hasher;
9pub use options::{
10    GenerateToken, HashToken, OneTimeTokenOptions, OneTimeTokenOptionsBuilder, OneTimeTokenSession,
11    StoreToken,
12};
13
14use rustauth_core::plugin::AuthPlugin;
15use rustauth_core::plugin::PluginAfterHookAction;
16
17pub const UPSTREAM_PLUGIN_ID: &str = "one-time-token";
18
19#[must_use]
20pub fn one_time_token(options: OneTimeTokenOptions) -> AuthPlugin {
21    AuthPlugin::new(UPSTREAM_PLUGIN_ID)
22        .with_version(crate::VERSION)
23        .with_options(options.to_value())
24        .with_endpoint(endpoints::generate_endpoint(options.clone()))
25        .with_endpoint(endpoints::verify_endpoint(options.clone()))
26        .with_async_after_hook("*", move |context, _request, response| {
27            let options = options.clone();
28            Box::pin(async move {
29                headers::set_ott_header_on_new_session(context, response, &options)
30                    .await
31                    .map(PluginAfterHookAction::Continue)
32            })
33        })
34}