omin

omin

Ueberauth Facebook edge case

(forgot the exact fb version number) it seems like users can choose not to share email during OAuth login. You can read more about it here: Issue · GitHub.

When users choose not to share their email, Ueberauth simply fails and does not ask for permission again. And because of this, users have no way to login.

For now, I’d like to force users to share their email. I found that we can do this by rerequesting Facebook OAuth permissions using
/auth/facebook?scope=email,public_profile&auth_type=rerequest but I’m not sure how to add this to Ueberauth.

Most Liked

lukerollans

lukerollans

See this section in the README, that should clear it up for you :slight_smile:
https://github.com/ueberauth/ueberauth_facebook#calling

If that doesn’t help, perhaps you could be more specific? Do you have a code example or an error message?

omin

omin

Hey @lukerollans, thanks for the reply. I actually got the idea of using /auth/facebook?scope=email,public_profile&auth_type=rerequest from the same source. I’ll try to be more specific using the phoenix guardian example (https://github.com/hassox/phoenix_guardian/blob/ueberauth-guardian/web/auth/user_from_auth.ex#L37).

Let’s add some basic code to check for an email.

defp validate_auth_for_registration(auth) do
  case auth.info.email do
    nil -> {:error, :email_is_null}
    "" -> {:error, :password_is_empty}
    _ -> :ok
  end
end

With this example, the authentication will get an {:error, :email_is_null} when the user doesn’t give permission for their email as expected. However, if the user realizes that the application needs his/her email and decides to try again, the user will get the error message without the permission prompt. I just found that you need to remove the app from https://www.facebook.com/settings?tab=applications to try again.

------- Update -------

It seems like this will do the trick.

  {:error, :email_is_null} ->
    conn
    |> redirect(to: "/auth/facebook?scope=email&auth_type=rerequest")

:grin:

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement