Ueberauth failed to assign %{ueberauth_auth: auth} structure for some reason

Hi guys, my code is failing the pattern match and I have no idea why? I think ueberauth is doing something funky. Following this tutorial.

[debug] Processing with AppWeb.AuthenticationController.identity_callback/2                                 [54/1956]
  Parameters: %{"user" => %{"email" => "reader@example.com", "password" => "[FILTERED]"}}
  Pipelines: [:api]
[info] Sent 400 in 62ms
[debug] ** (Phoenix.ActionClauseError) no function clause matching in AppWeb.AuthenticationController.identity_callback/2

Controller code:

 >>  7   def identity_callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
 >>  8     IO.inspect("does this work?")
 >>  9     #email = auth.uid
 >> 10     #password = auth.credentials.other.password
 >> 11     #handle_user_conn(Accounts.get_user_by_email_and_password(email, password), conn)
 >> 12   end

I use curl:

curl \
    -XPOST \
    -v \
    localhost:4000/api/auth/identity/callback \
    -H 'content-type: application/json' \
    -d '{"user": {"email": "reader@example.com", "password": "qweqweqwe"}}'

Thanks in advance

I’ve tested this function in iex -S mix and it works so I believe ueberauth is failing to assign the structure to my conn for some reason.

Have you checked using a catch-all clause what is actually comming into your function? Thats usually the first thing to do when debugging match-errors:

def identity_callback(conn, params) do
  IO.inspect(conn, label: :conn)
  IO.inspect(params, label: :params)

Thank you.

Got this message:

Request: POST /api/auth/identity/callback                                                                        [32/1957]
** (exit) an exception was raised:
    ** (RuntimeError) expected action/2 to return a Plug.Conn, all plugs must receive a connection (conn) and return a connection, got: %{"user" => %{"email" => "reader@example.com", "password" => "qweqweqwe"}}

It’s something to work on.


I got it thank you so much.

My config file was missing the base_path:

35 config :ueberauth, Ueberauth,
36   base_path: "/api/auth",

Thank you again!

1 Like

Hey, I had the same problem and adding base_path fixed it, but I don’t get why - as I understand this option isn’t required and it doesn’t even defied in the example repo. Do you have any idea why in our cases it was necessary to add the option? :thinking:

Do you have any idea why in our cases it was necessary to add the option?

Unfortunately I haven’t done this in a while. I also moved on in using the Pow library instead.

But I did a quick search.

Apparently the default is /auth and I want my path to be /api/auth. I’m assuming the router is like this and that the ueberauth library is expecting to auth on the path /auth. This is what I’m guessing is what happening.

I should document my solution and why it happen in the future. Thank you for pointing this out.

Yeah, I came to the same conclusion - I checked out today, and if I change routes to be prefixed with /auth, everything works without defining base_path. My problem was that I didn’t notice that routes in the example repo are prefixed with /auth via scope and for my app I took only what was inside of the scope, without /auth.

1 Like