pub struct MagicLinkPlugin<M, S>where
M: UserManager,
S: MagicLinkStorage,{ /* private fields */ }Expand description
Magic Link authentication plugin
This plugin provides magic link authentication functionality, allowing users to sign in by clicking a secure link sent to their email address rather than using a password.
§Features
- Generate secure one-time use magic links
- Verify magic link tokens
- Automatic user creation if not exists
§Example
use torii_auth_magic_link::MagicLinkPlugin;
use torii_core::{DefaultUserManager, plugin::PluginManager};
use std::sync::Arc;
// Create user manager
let user_manager = Arc::new(DefaultUserManager::new(user_storage.clone()));
// Register the plugin with your PluginManager
let mut plugin_manager = PluginManager::new(user_storage.clone(), session_storage.clone());
plugin_manager.register_plugin(MagicLinkPlugin::new(user_manager, user_storage.clone()));
// Generate a magic link token
let plugin = plugin_manager.get_plugin::<MagicLinkPlugin<DefaultUserManager<_>, _>>("magic_link").unwrap();
let token = plugin.generate_magic_token("user@example.com").await?;
// Verify the token when user clicks the link
let user = plugin.verify_magic_token(&token.token).await?;Implementations§
Source§impl<M, S> MagicLinkPlugin<M, S>where
M: UserManager,
S: MagicLinkStorage,
impl<M, S> MagicLinkPlugin<M, S>where
M: UserManager,
S: MagicLinkStorage,
pub fn new(user_manager: Arc<M>, magic_link_storage: Arc<S>) -> Self
pub async fn generate_magic_token( &self, email: &str, ) -> Result<MagicToken, MagicLinkError>
pub async fn verify_magic_token( &self, token: &str, ) -> Result<User, MagicLinkError>
Trait Implementations§
Source§impl<M, S> Plugin for MagicLinkPlugin<M, S>where
M: UserManager,
S: MagicLinkStorage,
impl<M, S> Plugin for MagicLinkPlugin<M, S>where
M: UserManager,
S: MagicLinkStorage,
Auto Trait Implementations§
impl<M, S> Freeze for MagicLinkPlugin<M, S>
impl<M, S> RefUnwindSafe for MagicLinkPlugin<M, S>where
M: RefUnwindSafe,
S: RefUnwindSafe,
impl<M, S> Send for MagicLinkPlugin<M, S>
impl<M, S> Sync for MagicLinkPlugin<M, S>
impl<M, S> Unpin for MagicLinkPlugin<M, S>
impl<M, S> UnwindSafe for MagicLinkPlugin<M, S>where
M: RefUnwindSafe,
S: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.