index.community/backend/lib/backend/auth.ex
2019-07-26 14:34:23 +00:00

18 lines
462 B
Elixir

defmodule Backend.Auth do
alias Phoenix.Token
import Backend.Util
@salt "fedi auth salt"
def get_login_link(domain) do
token = Token.sign(BackendWeb.Endpoint, @salt, domain)
frontend_domain = get_config(:frontend_domain)
"https://#{frontend_domain}/admin/verify?token=#{URI.encode(token)}"
end
def verify_token(token) do
# tokens are valid for 12 hours
Token.verify(BackendWeb.Endpoint, @salt, token, max_age: 43200)
end
end