AshAuthentication. BankID. Plug
(ash_authentication_bankid v0.1.3)
View Source
Plug handlers for BankID HTTP endpoints.
This module provides handlers for the three BankID phases:
initiate/2- Starts a BankID authentication and returns QR datapoll/2- Checks the status of an ongoing authenticationsign_in/2- Completes the authentication and returns a user with JWT token
Follows the pattern from MagicLink.Plug and OAuth2.Plug.
Summary
Functions
Initiate a BankID authentication order.
Poll the status of a BankID order.
Renew a BankID order by creating a new one.
Complete BankID authentication and sign in the user.
Functions
@spec initiate(Plug.Conn.t(), AshAuthentication.BankID.t()) :: Plug.Conn.t()
Initiate a BankID authentication order.
This endpoint:
- Generates a session ID and stores it in the Phoenix session
- Calls the BankID API to start authentication
- Creates an order record in the order resource
- Returns QR tokens (but NOT the secret!)
Expected response
Returns {:ok, data} with:
order_ref- Reference for polling and completionqr_start_token- Public token for QR code generationauto_start_token- Token for same-device flowstart_t- Timestamp for QR code generation
@spec poll(Plug.Conn.t(), AshAuthentication.BankID.t()) :: Plug.Conn.t()
Poll the status of a BankID order.
This endpoint:
- Gets the order from the database
- Calls BankID.collect to check status
- Updates the order in the database
- Returns the current status
This does NOT complete the authentication - it just returns status info.
Parameters
Expects order_ref in the query params.
Response
Returns {:ok, data} with:
status- "pending", "complete", or "failed"hint_code- BankID hint code for user messaging
@spec renew(Plug.Conn.t(), AshAuthentication.BankID.t()) :: Plug.Conn.t()
Renew a BankID order by creating a new one.
This endpoint:
- Validates the current order exists and matches session
- Creates a new BankID order with same session_id and ip_address
- Cancels the old order via BankID.cancel
- Deletes the old order from database
- Returns new order data (qr_start_token, auto_start_token, start_t)
Parameters
Expects order_ref in params (the current order to renew).
Response
Returns {:ok, data} with new order_ref, qr_start_token, auto_start_token, start_t
@spec sign_in(Plug.Conn.t(), AshAuthentication.BankID.t()) :: Plug.Conn.t()
Complete BankID authentication and sign in the user.
This endpoint:
- Validates the order is complete
- Calls the sign_in action which handles user creation/update
- Returns the user with JWT token in metadata
Parameters
Expects order_ref in the params.
Response
Returns {:ok, user} with JWT token in metadata.