I use Ruby on Rails, gem omniauth-vkontakte. when trying to authenticate, the VK displays {"error":"invalid_client","error_description":"client_id is incorrect"} , in the heroku logs: NoMethodError (undefined method 'provider' for nil:NilClass): app/models/user.rb:5:in 'from_omniauth' app/controllers/sessions_controller.rb:3:in 'create'

app_id and app_secret are correct, checked several times: (

config/initializers/omniauth.rb :

 Rails.application.config.middleware.use Omniauth::Builder do provider :vkontakte, ENV['app_id'], ENV['app_secret'], scope: 'public_profile', display: 'page', image-size: 'square' end 

models/user.rb :

 class User < ActiveRecord::Base has_many :messages, dependent: :delete_all class << self def from_omniauth(auth) provider = auth.provider uid = auth.uid info = auth.info.symbolize.keys! user = User.find_or_initialize_by(uid: uid, provider: provider) user.name = info.name user.avatar_url = info.image user.profile_url = info.urls.send(provider.capitalize.to_sym) user.save! user end end end 

controllers/sessions_controller.rb :

 def create user = User.from_omniauth(request.env['omniauth_auth']) cookies[:user_id] = user.id redirect_to root_path end 

    1 answer 1

    • The fifth line of user.rb , allegedly calling the #provider method of nil .
    • Apparently, auth is nil . How did that happen?
    • In the first line of SessionsController#create in place of auth request.env['omniauth_auth']

    ...

    Well, yes, there is nil , there is no such key in the env (environment) request. The key is not the same .

    Instead of omniauth_auth needed.

    - intridea/OmniAuth/README.md

     def auth_hash request.env['omniauth.auth'] end 
    • thank! overlooked this error, corrected, now it does not appear in the logs, but the VC itself still passes {"error":"invalid_client","error_description":"client_id is incorrect"} . I rechecked the app_id and app_secret given to me several times, that's right - AlexNikolaev94
    • @ AlexNikolaev94 is another question for which I have no information to answer. There is no magic, apparently, you have somehow made a mistake. Observe what requests the client browser makes; the problem will probably be noticeable even there. - D-side
    • main query goes to method=GET path="/auth/vkontakte" - AlexNikolaev94
    • fixed, just redirect URI is not the one indicated in the application settings, deleted it - and it worked :) - AlexNikolaev94