ueberauth / ueberauth_vk

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

Error after successful authentication: "no function clause matching in List.first/1" #38

Closed mikatuo closed 6 years ago

mikatuo commented 6 years ago

When user is authenticated and callback (/auth/vk/callback) is called it fails to fetch user info from VK API due to the "Invalid request: v (version) is required" error.

How To Reproduce

  1. Try authenticating by calling /auth/vk
  2. After being redirected back to /auth/vk/callback?code=xxx it will show the error (see Stack Trace).

Stack Trace

Request: GET /auth/vk/callback?code=a55b8166fcf0135cf6
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in List.first/1
        (elixir) lib/list.ex:219: List.first(nil)
        (ueberauth_vk) lib/ueberauth/strategy/vk.ex:173: Ueberauth.Strategy.VK.fetch_user/3
        (ueberauth) lib/ueberauth/strategy.ex:301: Ueberauth.Strategy.run_callback/2
        (my_app) lib/my_app_web/controllers/auth_controller.ex:1
        ...

The users.get API returns a response:

STATUS_CODE: 200
%{"error" => %{"error_code" => 8,
    "error_msg" => "Invalid request: v (version) is required",
    "request_params" => [%{"key" => "oauth", "value" => "1"},
     %{"key" => "method", "value" => "users.get"},
     %{"key" => "fields", "value" => ""},
     %{"key" => "user_ids", "value" => "84294762"}]}}

Suggested Fix

  1. Add a test case for this bug
  2. Fix by adding |> Map.merge(%{"v" => "5.73"}) to the method user_query at vk.ex solves the error.
sobolevn commented 6 years ago

Yeap, that true. You can now use https://github.com/sobolevn/ueberauth_vk/pull/37

I will release a new version shortly.