ueberauth / guardian

Elixir Authentication
MIT License
3.43k stars 382 forks source link

Decode and Verify /1 doesn't exist? (v1.2.1) #603

Closed patientplatypus closed 5 years ago

patientplatypus commented 5 years ago

This weird warning doesn't seem to follow the docs:

warning: function Guardian.decode_and_verify/1 is undefined or private. Did you mean one of:

      * decode_and_verify/2
      * decode_and_verify/3
      * decode_and_verify/4

Code:

defp authorize(token) do
    case Guardian.decode_and_verify(token) do
      {:ok, claims} -> return_user(claims)
      {:error, reason} -> {:error, reason}
    end
 end

And check out this:

{:ok, claims} = MyApp.Guardian.decode_and_verify(token)

From here: https://hexdocs.pm/guardian/Guardian.html

What is going on here? Are the docs inaccurate, or is the test inaccurate? My code is very simple and it should work as it's almost a direct implementation.

patientplatypus commented 5 years ago

I'm going to try and get it to work by passing empty vals to the extra arity -

case Guardian.decode_and_verify(token, %{}, []) do

It compiles, but I'm not sure it will work.

backspace commented 5 years ago

I think you’re meant to be using a module that has use Guardian; notice the MyApp in the example. If you don’t access it that way, you can pass the module that has use Guardian as the first argument to Guardian.decode_and_verify.

patientplatypus commented 5 years ago

I'm trying to follow this guide but it may be broken: https://gist.github.com/posilva/4fc69fcb71e463a7f00198b612522d39#file-context-ex-L30. It's non-official of course, so I think it's a misimplementation. Thanks for the help.

backspace commented 5 years ago

hmm, maybe that’s for Guardian 0.14 or older, as I see Guardian.decode_and_verify/1 in the documentation.

yordis commented 5 years ago

That is the old API, you must use your own instance of Guardian module in the latest version of Guardian.

{:ok, claims} = MyApp.Guardian.decode_and_verify(token)