简体   繁体   中英

Guardian 1.0 failing auth when using key option

I'm using the library Guardian 1.0 with an auth pipeline defined like this:

defmodule DokkitoWeb.Plug.GuardianPipeline do
  use Guardian.Plug.Pipeline, otp_app: :dokkito,
                          module: DokkitoWeb.Guardian,
                          error_handler: DokkitoWeb.Plug.AuthErrorHandler,
                          key: :user

  plug Guardian.Plug.VerifySession
  plug Guardian.Plug.EnsureAuthenticated
  plug Guardian.Plug.LoadResource
end

My sign in code in the controller is doing:

DokkitoWeb.Guardian.Plug.sign_in(conn, user, key: :user)

When going through the pipeline I'm getting

{
  "message": "unauthenticated"
}

If I remove key: :user in both sign_in call and the pipeline it's authenticating fine. What am I doing wrong?

Basically I needed to write : conn = Guardian.Plug.sign_in(conn, user, %{}, key: :user) otherwise the key was added to the claims instead of the options. My god that was complicated to debug...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM