ueberauth / ueberauth_vk

vk.com OAuth2 Strategy for Überauth.
https://hex.pm/packages/ueberauth_vk
MIT License
19 stars 12 forks source link

Image fetching doesn't work correctly #2

Closed JustMikey closed 8 years ago

JustMikey commented 8 years ago

The pattern matching breaks here because user seems to be just a map, not a tuple.

sobolevn commented 8 years ago

What's your setup? This is working for me.

The pattern match is done by the last pipe operator result:

{_, photo_url} =
      user
      |> Enum.filter(fn {k, _v} -> String.starts_with?(k, "photo_") end)
      |> Enum.sort_by(fn {"photo_" <> size, _v} -> Integer.parse(size) end)
      |> List.last

Since VK has different attributes for images like: photo_50, photo_100 and so on, what we do here is:

  1. Filter only attributes starting with photo_
  2. Sort it by size
  3. Get the biggest as a tuple: {photo_size, photo_url}

Proof:

2016-05-07 12 19 12
JustMikey commented 8 years ago

That's my foolish mistake, I had a quick look and didn't get it correctly. Anyway, as far as I know, those fields, photo_50, photo_100 and so on should be requested in the users.get request (the fields param) but it doesnt look like they are by default.

sobolevn commented 8 years ago

You have to configure the non-default fields in your app's settings:

config :ueberauth, Ueberauth,
  providers: [
    vk: { Ueberauth.Strategy.VK, [profile_fields: "photo_100,sex,bdate"] }
  ]

I found a bug you were talking about. If missing any photo_* params the code will fail. Fixed that already. I will push it with other improvements shortly.

Thanks!

JustMikey commented 8 years ago

Yeah I know, It just should be default if it's always assumed that those fields are present :) And thank you for fixing it so fast :)

sobolevn commented 8 years ago

Any feedback is welcomed. If everything is cool, I will create a new release.