mirror of
https://github.com/teslamate-org/teslamate.git
synced 2026-01-24 21:06:08 +08:00
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.
22 lines
415 B
Elixir
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
|