AshAuthentication.BankID.Helpers (ash_authentication_bankid v0.1.1)
View SourceHelper functions for BankID LiveView implementations.
This module provides utility functions commonly needed when building BankID authentication flows in Phoenix LiveView.
Summary
Functions
Generates a cryptographically secure random session ID.
Returns the poll interval in milliseconds.
Returns the QR update interval in milliseconds.
Returns the renewal interval in milliseconds.
Schedules a BankID status poll after the configured interval.
Schedules a QR code content update after the configured interval.
Schedules a BankID order renewal after the configured interval.
Functions
@spec generate_session_id() :: String.t()
Generates a cryptographically secure random session ID.
Returns a URL-safe base64-encoded string of 32 random bytes.
Examples
iex> session_id = AshAuthentication.BankID.Helpers.generate_session_id()
iex> is_binary(session_id)
true
iex> byte_size(session_id) > 40
true
@spec poll_interval() :: pos_integer()
Returns the poll interval in milliseconds.
Examples
iex> AshAuthentication.BankID.Helpers.poll_interval()
2000
@spec qr_update_interval() :: pos_integer()
Returns the QR update interval in milliseconds.
Examples
iex> AshAuthentication.BankID.Helpers.qr_update_interval()
1000
@spec renewal_interval() :: pos_integer()
Returns the renewal interval in milliseconds.
Examples
iex> AshAuthentication.BankID.Helpers.renewal_interval()
28000
@spec schedule_poll() :: :ok
Schedules a BankID status poll after the configured interval.
Sends a :poll_status message to the current process after 2000ms (2 seconds).
This adheres to BankID's requirement to poll at least 2 seconds apart.
Examples
iex> AshAuthentication.BankID.Helpers.schedule_poll()
:ok
@spec schedule_qr_update() :: :ok
Schedules a QR code content update after the configured interval.
Sends an :update_qr_content message to the current process after 1000ms (1 second).
QR codes must be regenerated every second using BankID's time-based HMAC algorithm.
Examples
iex> AshAuthentication.BankID.Helpers.schedule_qr_update()
:ok
@spec schedule_renewal() :: :ok
Schedules a BankID order renewal after the configured interval.
Sends a :renew_order message to the current process after 28000ms (28 seconds).
Orders are renewed before BankID's 30-second timeout to maintain authentication sessions.
Examples
iex> AshAuthentication.BankID.Helpers.schedule_renewal()
:ok