authenticate callback arity for token cookie module is incorrect
jhefreyzz opened this issue · 2 comments
Environment
- Elixir & Erlang/OTP versions (elixir --version):
Erlang/OTP 22 [erts-10.6.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Elixir 1.9.4 (compiled with Erlang/OTP 21) - Operating system: Windows 10 / WSL Ubuntu
Issue
It seems like the arity for authenticate callback is incorrect. Based on the guide from the docs: https://hexdocs.pm/phauxth/Phauxth.Authenticate.Token.html, the function is authenticate/2.
I implemented the same way since I'm using cookie to store the token but Phauxth.Authenticate.Token expects authenticate/3.
My implementation:
defmodule ShiritoriWeb.Auth.AuthenticateTokenCookie do
use Phauxth.Authenticate.Token
@impl true
def authenticate(%Plug.Conn{req_cookies: %{"token" => token}}, opts) do
verify_token(token, opts, opts)
end
end
The warning from ElixirLS:
got "@impl true" for function authenticate/2 but no behaviour specifies such callback. The known callbacks are:
* Phauxth.Authenticate.Base.authenticate/3 (function)
* Plug.call/2 (function)
* Phauxth.Authenticate.Token.get_token/3 (function)
* Plug.init/1 (function)
* Phauxth.Authenticate.Base.report/2 (function)
* Phauxth.Authenticate.Base.set_user/2 (function)
furthermore verify_token
expects 3 parameters but the verify_token
from the guide I'm referring to, only pass 2 parameters.
From the docs:
defmodule Phauxth.AuthenticateTokenCookie do
use Phauxth.Authenticate.Token
@impl true
def authenticate(%Plug.Conn{req_cookies: %{"access_token" => token}}, opts) do
verify_token(token, opts)
end
end
I found a workaround but involves removing the @impl true
for the authenticate/2
and passing opts to 2nd and 3rd parameter of verify_token
:
def authenticate(%Plug.Conn{req_cookies: %{"token" => token}}, opts) do
verify_token(token, opts, opts)
end
Thanks for pointing that out. It looks like the examples in the documentation are wrong.
The example should be:
defmodule Phauxth.AuthenticateTokenCookie do
use Phauxth.Authenticate.Token
@impl true
def authenticate(%Plug.Conn{req_cookies: %{"access_token" => token}}, user_context, opts) do
verify_token(token, user_context, opts)
end
end
And I will update the docs later this week.
Documentation updated in version 2.3.2