Class: Fizzy::MagicLinkFlow
- Inherits:
-
Object
- Object
- Fizzy::MagicLinkFlow
- Defined in:
- lib/fizzy/magic_link_flow.rb
Overview
Orchestrates the passwordless magic link authentication flow.
The flow works in two steps:
-
Call CreateSession with an email address - this sends a magic link email
-
Call RedeemMagicLink with the token from the magic link URL
After redemption, the response contains a session token that can be used with CookieAuth or BearerAuth for subsequent requests.
Defined Under Namespace
Classes: NullAuth
Instance Method Summary collapse
-
#initialize(base_url: Config::DEFAULT_BASE_URL, hooks: nil) ⇒ MagicLinkFlow
constructor
A new instance of MagicLinkFlow.
-
#redeem(token:) ⇒ Hash
Step 2: Redeem a magic link token to get a session.
-
#request_magic_link(email:) ⇒ Hash
Step 1: Request a magic link email.
Constructor Details
#initialize(base_url: Config::DEFAULT_BASE_URL, hooks: nil) ⇒ MagicLinkFlow
Returns a new instance of MagicLinkFlow.
23 24 25 26 27 |
# File 'lib/fizzy/magic_link_flow.rb', line 23 def initialize(base_url: Config::DEFAULT_BASE_URL, hooks: nil) @config = Config.new(base_url: base_url) @hooks = hooks || NoopHooks.new @http = Http.new(config: @config, auth_strategy: NullAuth.new, hooks: @hooks) end |
Instance Method Details
#redeem(token:) ⇒ Hash
Step 2: Redeem a magic link token to get a session.
42 43 44 45 |
# File 'lib/fizzy/magic_link_flow.rb', line 42 def redeem(token:) response = @http.post("/sessions/redeem", body: { token: token }) response.json end |
#request_magic_link(email:) ⇒ Hash
Step 1: Request a magic link email.
33 34 35 36 |
# File 'lib/fizzy/magic_link_flow.rb', line 33 def request_magic_link(email:) response = @http.post("/sessions", body: { email: email }) response.json end |