Answer the question
In order to leave comments, you need to log in
Why doesn't Devise authorize the omniauth-vkontakte gem?
I do authorization Devise+Omniauth+google+facebook+vk. Everything works except for the omniauth-vkontakte gem, when clicked, authorization does not occur, but throws at domain/users/sign_up, what could be the error?
app/models/user.rb
devise :omniauthable, :omniauth_providers => [:google_oauth2, :facebook, :vkontakte]
def self.find_for_vkontakte_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
if user
return user
else
registered_user = User.where(:email => auth.info.email).first
if registered_user
return registered_user
else
user = User.create(name:auth.extra.raw_info.name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20],
)
end end
end
app/controllers/users/omniauth_callbacks_controller.rb
def vkontakte
@user = User.find_for_vkontakte_oauth(request.env["omniauth.auth"], current_user)
if @user.persisted?
set_flash_message(:notice, :success, :kind => "Vkontakte") if is_navigational_format?
sign_in_and_redirect @user, :event => :authentication
else
session["devise.vkontakte_data"] = request.env["omniauth.auth"].except("extra")
redirect_to new_user_registration_url
end
end
config/initializers/devise.rb
config.omniauth :vkontakte, "546546545", "fdgnG1fdgxgVefdgO",
{
:scope => 'friends,audio,photos',
:display => 'popup',
:lang => 'en',
:image_size => 'original'
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question