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
See this section in the README, that should clear it up for you ![]()
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
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")
![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









