ueberauth / guardian_db

Guardian DB integration for tracking tokens and ensuring logout cannot be replayed.
MIT License
367 stars 87 forks source link

Throwing "no case clause matching" when use with GuardianDB #33

Closed yuchunc closed 7 years ago

yuchunc commented 7 years ago

Hi, I upgraded the to the latest Guardian package, and ran in to this exception:

** (exit) an exception was raised:
    ** (CaseClauseError) no case clause matching: {:ok, {%ElixirTw.User{__meta__: #Ecto.Schema.Metadata<:loaded, "users">, crypted_password: nil, email: "poverwhelming@gmail.com", id: 1, inserted_at: #Ecto.DateTime<2016-10-01 14:38:47>, name: "Mickey Chen", oauth_infos: #Ecto.Association.NotLoaded<association :oauth_infos is not loaded>, posts: #Ecto.Association.NotLoaded<association :posts is not loaded>, updated_at: #Ecto.DateTime<2016-10-01 14:38:47>}, nil, %{"aud" => "User:1", "exp" => 1485240250, "iat" => 1482648250, "iss" => "ElixirTW", "jti" => "ea6a199e-4e52-4472-96f9-e84ef0ad4dc1", "pem" => %{}, "sub" => "User:1", "typ" => "access"}, "eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJVc2VyOjEiLCJleHAiOjE0ODUyNDAyNTAsImlhdCI6MTQ4MjY0ODI1MCwiaXNzIjoiRWxpeGlyVFciLCJqdGkiOiJlYTZhMTk5ZS00ZTUyLTQ0NzItOTZmOS1lODRlZjBhZDRkYzEiLCJwZW0iOnt9LCJzdWIiOiJVc2VyOjEiLCJ0eXAiOiJhY2Nlc3MifQ.AZUR4vzOGuYFEW3z1vvms4VZjPGR6EC4XBjL0Hvmax3CSiU_uyLe7CIpUvXpybmo59MTZZN0ouOFvuaznPuQhDcAAMuUVRWgMjQmJRmJUzr0uEbvm3H-JBVZs0tp-FbtT8rLfC2ZuxAvob8G5v8GPpIObWlUO8LOiUaBD0aw2oWudyiq"}}
        (guardian) lib/guardian.ex:100: Guardian.encode_from_hooked/1
        (guardian) lib/guardian/plug.ex:117: Guardian.Plug.sign_in/4
        (elixir_tw) web/controllers/session_controller.ex:51: ElixirTw.SessionController.callback/2
        (elixir_tw) web/controllers/session_controller.ex:1: ElixirTw.SessionController.action/2
        (elixir_tw) web/controllers/session_controller.ex:1: ElixirTw.SessionController.phoenix_controller_pipeline/2
        (elixir_tw) lib/elixir_tw/endpoint.ex:1: ElixirTw.Endpoint.instrument/4
        (elixir_tw) lib/phoenix/router.ex:261: ElixirTw.Router.dispatch/2
        (elixir_tw) web/router.ex:1: ElixirTw.Router.do_call/2
        (elixir_tw) lib/elixir_tw/endpoint.ex:1: ElixirTw.Endpoint.phoenix_pipeline/1
        (elixir_tw) lib/plug/debugger.ex:123: ElixirTw.Endpoint."call (overridable 3)"/2
        (elixir_tw) lib/elixir_tw/endpoint.ex:1: ElixirTw.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

after some digging into the code I think it's a miss match between:

GuardianDb's [after_encode_and_sign] (https://github.com/hassox/guardian_db/blob/master/lib/guardian_db.ex#L77)

and

Guardian's https://github.com/ueberauth/guardian/blob/master/lib/guardian.ex#L105

If we just tweak the pattern a little bit to {:ok, _} it would resolve the issue.

yuchunc commented 7 years ago

I posted this in the wrong place. This should be in Guardian project, not GuardianDb.

Sorry for the confusing.