Files
archived-hipudding-teslamate/lib/teslamate/auth/tokens.ex
Adrian Kumpf 0d6e288c70 Encrypt API tokens (#2360)
Store API tokens encrypted in the database.

During the database migration a randomly generated key will be used encrypt the tokens if no ENCRYPTION_KEY environment variable was provided.

If the application is started without the presence of an ENCRYPTION_KEY (or if the key failed to decrypt the existing tokens), the UI will display a warning with further instructions.
2022-02-18 17:03:13 +01:00

22 lines
415 B
Elixir

defmodule TeslaMate.Auth.Tokens do
use Ecto.Schema
import Ecto.Changeset
alias TeslaMate.Vault.Encrypted
schema "tokens" do
field :refresh, Encrypted.Binary, redact: true
field :access, Encrypted.Binary, redact: true
timestamps()
end
@doc false
def changeset(tokens, attrs) do
tokens
|> cast(attrs, [:access, :refresh])
|> validate_required([:access, :refresh])
end
end