AshAuthentication.BankID (ash_authentication_bankid v0.1.3)

View Source

Strategy for authentication using Swedish BankID.

This authentication strategy provides integration with Swedish BankID, supporting both QR code (cross-device) and same-device authentication flows.

Features

  • QR code-based authentication for desktop users
  • Same-device authentication for mobile users
  • Automatic user creation/update via upsert pattern
  • Session binding for security
  • Order expiration and cleanup

Configuration

Configure the strategy in your user resource:

authentication do
  strategies do
    bank_id do
      order_resource MyApp.Accounts.BankIDOrder
      personal_number_field :personal_number
      given_name_field :given_name
      surname_field :surname
      verified_at_field :bankid_verified_at
      ip_address_field :ip_address
      order_ttl 180
      poll_interval 2000
    end
  end
end

User Resource Requirements

Your user resource must have:

  • An identity on the configured identity_field (default: :personal_number)
  • Tokens enabled
  • The required attribute fields configured above

Order Resource

You must create an order resource to track BankID authentication sessions. See AshAuthentication.BankID.OrderResource for details.

Security

  • QR start secrets are never sent to the client
  • Orders are bound to Phoenix sessions
  • Orders expire after the configured TTL (default: 3 minutes)
  • Orders are single-use (marked as consumed after completion)

Summary

Types

t()

@type t() :: %AshAuthentication.BankID{
  __spark_metadata__: Spark.Dsl.Entity.spark_meta(),
  cleanup_interval: pos_integer(),
  consumed_order_ttl: pos_integer(),
  given_name_field: atom(),
  identity_field: atom(),
  ip_address_field: atom(),
  name: atom(),
  order_resource: module(),
  order_ttl: pos_integer(),
  personal_number_field: atom(),
  poll_interval: pos_integer(),
  resource: module(),
  sign_in_action_name: atom(),
  surname_field: atom(),
  verified_at_field: atom()
}

Functions

transform(entity, dsl_state)

Callback implementation for AshAuthentication.Strategy.Custom.transform/2.

verify(strategy, dsl_state)

Callback implementation for AshAuthentication.Strategy.Custom.verify/2.