ueberauth / guardian

Elixir Authentication
MIT License
3.44k stars 381 forks source link

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

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

Apologies if I didn't do the pull request right, I am not familiar to the proper way of contributing to a project. Please let me know if I'm missing anything, I will patch it.

doomspork commented 7 years ago

Thanks for the report @yuchunc 👍 I'll take a peek at your PR today.

jamesvl commented 7 years ago

Yep, I'm getting the same thing. Applying PR #243 fixed it locally. (Until it's merged I can't use it in my CI system, of course.)

jamesvl commented 7 years ago

Any idea on when you'll cut a new release for hex.pm? This will remain broken for anyone until then.

doomspork commented 7 years ago

@jamesvl I intend to cut a new release today but in the meantime you can use master:

{:guardian, github: "ueberauth/guardian"}
doomspork commented 7 years ago

0.14.1 has been released.

collegeimprovements commented 7 years ago

Hi, I got this error even after the upgrade. I got the same error with 0.14.1.

larryweya commented 7 years ago

Same issue as @collegeimprovements after upgrade to 0.14.1. Found the issue and opened a pull request #250

doomspork commented 7 years ago

@larryweya / @collegeimprovements / @NilsLattek — a fix has been merged into master, before I cut a new release could one of you please verify that master is working for you? I'm currently traveling and don't have everything I need to smoke test it.

Ch4s3 commented 7 years ago

@doomspork I was having the same problem and using {:guardian, github: "ueberauth/guardian"} fixes it for me.

Is this the fix?

larryweya commented 7 years ago

@doomspork works for me too.

doomspork commented 7 years ago

Thank you @Ch4s3 and @larryweya 👍

doomspork commented 7 years ago

I've released 0.14.2, hopefully this resolves everyone's issues. The ueberauth org is taking over GuardianDB maintenance so I'll be putting some time into clean-up in the coming weeks.

jacktang commented 7 years ago

I am facing the same problem and 0.14.2 works fine

Ch4s3 commented 7 years ago

Can confirm, 0.14.2 works