ash_authentication/dev/dev_server/token_check.ex
James Harton a939dde9b9
feat(PasswordAuthentication): Registration and authentication with local credentials (#4)
This is missing a bunch of features that you probably want to use (eg confirmation, password resets), but it's a pretty good place to put a stake in the sand and say it works.
2022-10-25 11:07:07 +13:00

26 lines
584 B
Elixir

defmodule DevServer.TokenCheck do
@moduledoc """
Verifies a submitted token and reports the contents.
"""
@behaviour Plug
alias AshAuthentication.Jwt
alias Plug.Conn
@doc false
@impl true
@spec init(keyword) :: keyword
def init(opts), do: opts
@doc false
@impl true
@spec call(Conn.t(), any) :: Conn.t()
def call(%{params: %{"token" => token}} = conn, _opts) do
result = Jwt.verify(token, :ash_authentication)
conn
|> Conn.send_resp(200, inspect(result))
end
def call(conn, _opts), do: Conn.send_resp(conn, 200, "Invalid request")
end