AshAuthentication.BankID.Helpers (ash_authentication_bankid v0.1.1)

View Source

Helper 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

generate_session_id()

@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

poll_interval()

@spec poll_interval() :: pos_integer()

Returns the poll interval in milliseconds.

Examples

iex> AshAuthentication.BankID.Helpers.poll_interval()
2000

qr_update_interval()

@spec qr_update_interval() :: pos_integer()

Returns the QR update interval in milliseconds.

Examples

iex> AshAuthentication.BankID.Helpers.qr_update_interval()
1000

renewal_interval()

@spec renewal_interval() :: pos_integer()

Returns the renewal interval in milliseconds.

Examples

iex> AshAuthentication.BankID.Helpers.renewal_interval()
28000

schedule_poll()

@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

schedule_qr_update()

@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

schedule_renewal()

@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