summaryrefslogtreecommitdiff
path: root/lib/chessh/auth/keys.ex
diff options
context:
space:
mode:
authorSimponic <loganhunt@simponic.xyz>2022-12-19 20:45:01 -0700
committerSimponic <loganhunt@simponic.xyz>2022-12-19 20:45:01 -0700
commit110eb0b1990d5d5ee77f9368a9b7653cfdc07131 (patch)
treebfe5744255cdfbdc9412d148236a2bf5f8aad7c1 /lib/chessh/auth/keys.ex
parentfe661a935ac887b11aec31ff049ace2db7ccbf84 (diff)
downloadchessh-110eb0b1990d5d5ee77f9368a9b7653cfdc07131.tar.gz
chessh-110eb0b1990d5d5ee77f9368a9b7653cfdc07131.zip
Implement public key and add tests
Diffstat (limited to 'lib/chessh/auth/keys.ex')
-rw-r--r--lib/chessh/auth/keys.ex17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/chessh/auth/keys.ex b/lib/chessh/auth/keys.ex
index d85f4a4..a948fdf 100644
--- a/lib/chessh/auth/keys.ex
+++ b/lib/chessh/auth/keys.ex
@@ -1,10 +1,19 @@
defmodule Chessh.Auth.KeyAuthenticator do
+ alias Chessh.Key
+ alias Chessh.Repo
use Sshd.PublicKeyAuthenticator
require Logger
+ import Ecto.Query
- def authenticate(username, public_key, _opts) do
- Logger.debug("#{inspect(username)}")
- Logger.debug("#{inspect(public_key)}")
- true
+ def authenticate(username, public_key) do
+ !!Repo.one(
+ from(k in Key,
+ join: p in assoc(k, :player),
+ where: k.key == ^Key.encode_key(public_key),
+ where: p.username == ^String.Chars.to_string(username)
+ )
+ )
end
+
+ def authenticate(username, public_key, _opts), do: authenticate(username, public_key)
end