Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authenticate callback arity for token cookie module is incorrect #114

Closed
jhefreyzz opened this issue Feb 24, 2020 · 2 comments
Closed

authenticate callback arity for token cookie module is incorrect #114

jhefreyzz opened this issue Feb 24, 2020 · 2 comments
Assignees

Comments

@jhefreyzz
Copy link

jhefreyzz commented Feb 24, 2020

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
@riverrun
Copy link
Owner

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.

@riverrun
Copy link
Owner

riverrun commented Mar 1, 2020

Documentation updated in version 2.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants