Add Guardian.DB to track API tokens.

This commit is contained in:
2024-08-31 14:32:08 +03:00
parent 8697be9f17
commit 2f4fc790be
6 changed files with 54 additions and 4 deletions
+24
View File
@@ -28,4 +28,28 @@ defmodule LinkShortenerWeb.Auth.Guardian do
{:ok, token, _claims} = encode_and_sign(user)
{:ok, user, token}
end
def after_encode_and_sign(resource, claims, token, _options) do
with {:ok, _} <- Guardian.DB.after_encode_and_sign(resource, claims["typ"], claims, token) do
{:ok, token}
end
end
def on_verify(claims, token, _options) do
with {:ok, _} <- Guardian.DB.on_verify(claims, token) do
{:ok, claims}
end
end
def on_refresh({old_token, old_claims}, {new_token, new_claims}, _options) do
with {:ok, _, _} <- Guardian.DB.on_refresh({old_token, old_claims}, {new_token, new_claims}) do
{:ok, {old_token, old_claims}, {new_token, new_claims}}
end
end
def on_revoke(claims, token, _options) do
with {:ok, _} <- Guardian.DB.on_revoke(claims, token) do
{:ok, claims}
end
end
end