phoenix_passkeys/lib/phoenix_passkeys/accounts/user_credential.ex

26 lines
658 B
Elixir

defmodule PhoenixPasskeys.Accounts.UserCredential do
@moduledoc """
A WebAuthn credential belonging to a particular user.
"""
use Ecto.Schema
import Ecto.Changeset
# Use a binary as the ID, since that's what we get from WebAuthn for the credential.
@primary_key {:id, :binary, []}
schema "users_credentials" do
# DER Subject Public Key Info: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.7
field :public_key_spki, :binary
belongs_to :user, PhoenixPasskeys.Accounts.User
timestamps()
end
def changeset(credential, attrs) do
credential
|> cast(attrs, [:id, :public_key_spki, :user_id])
end
end