mirror of
https://github.com/team-alembic/ash_authentication.git
synced 2024-09-20 05:13:10 +12:00
a939dde9b9
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.
26 lines
584 B
Elixir
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
|