ueberauth / ueberauth_facebook

Facebook OAuth2 Strategy for Überauth.
MIT License
77 stars 64 forks source link

fetch_user/2, inject locale param #10

Closed hykw closed 8 years ago

hykw commented 8 years ago

Facebook has your name not only written in English(alphabet), but in language-specific name such as Umlaut, Japanese kanji, etc(I attache the snapshots, just in case).

You can get the language-specific name with https://graph.facebook.com/me?locale=ja_JP&access_token=xxxxxx. Is it possible to specify locale when you fetch user data?(maybe injecting it in fetch_user/2, path parameter)

facebook1

facebook2

doomspork commented 8 years ago

Hey @hykw, can you check out the latest version? I just released a new version with the changes @hassox made in #11

hykw commented 8 years ago

No, it doesn't work.

It seems locale is added to authorize_url, but it should be specified when you fetch user info(in fetch_user/2, line 134: path = "/me?fields=#{option(conn, :profile_fields)}&locale=ja_JP"), because authorization process doesn't need any locale information, but fetching user info does.

My configuration is following, btw.

config :ueberauth, Ueberauth,
  providers: [
    facebook: {Ueberauth.Strategy.Facebook, [
        profile_fields: "name,email",
        request_path: "/social_login/facebook",
        callback_path: "/social_login/facebook_callback/",
        auth_type: "rerequest",
        locale: "ja_JP",
    ]}
  ]
hassox commented 8 years ago

I think you will need to define a list of allowed_request_params

If you look in lib/strategies/facebook.ex you can see the defaults

doomspork commented 8 years ago

@hassox I think what @hykw is suggesting is that we need to update fetch_user/2:

defp fetch_user(conn, token) do
  conn = put_private(conn, :facebook_token, token)
  path = "/me?fields=#{option(conn, :profile_fields)}"
  case OAuth2.AccessToken.get(token, path) do
   # do stuff
  end
end

To something like:

defp fetch_user(conn, token) do
  conn = put_private(conn, :facebook_token, token)
  path = "/me?fields=#{option(conn, :profile_fields)}&locale=#{option(conn, :locale)}"
  case OAuth2.AccessToken.get(token, path) do
   # do stuff
  end
end

@hykw do you know the default locale is?

hykw commented 8 years ago

@doomspork Yes, that's what I thought. locale option have to be set to https://graph.facebook.com/me

@hykw do you know the default locale is?

The default locale is empty(/me?fields=#{option(conn, :profile_fields)}), because you, includes Facebook, cannot determine the default(because it's not lang but locale, such as, en_CA, en_us. en_GB, etc...).

doomspork commented 8 years ago

@hykw I opened a PR with a new change I think should solve this for you. Can you take a peek at #13 when you have a chance?

Thanks!