Answer the question
In order to leave comments, you need to log in
[Rails] Devise Omniauth + Vkontakte. When trying to login "Not found. Authentication passthru." What's the matter?
Hello!
I do authentication through VKontakte. I use gems devise, omniauth, omniauth-vkontakte.
When I click on the link to log in through VKontakte, a message-page appears ( localhost:8080/users/auth/vkontakte.user):
"Not found. Authentication passthru."
In the initialization of devise.rb :
where 'APP_ID', 'APP_SECRET' are the values obtained when registering the application on the VKontakte server
, model user.rb :config.omniauth :vkontakte, 'APP_ID', 'APP_SECRET'
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable,
:omniauthable, omniauth_providers: [:vkontakte]
attr_accessor :email, :password, :password_confirmation, :remember_me
attr_accessor :nickname, :provider, :url, :username
def self.find_for_vkontakte_oauth access_token
if user = User.where(:url => access_token.info.urls.Vkontakte).first
user
else
User.create!(:provider => access_token.provider, :url => access_token.info.urls.Vkontakte, :username => access_token.info.name, :nickname => access_token.extra.raw_info.domain, :email => access_token.extra.raw_info.domain+'<hh user=vk>.com', :password => Devise.friendly_token[0,20])
end
end
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
include Devise::Controllers::Rememberable
def facebook
end
def vkontakte
@user = User.find_for_vkontakte_oauth request.env["omniauth.auth"]
if @user.persisted?
remember_me(@user)
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Vkontakte"
sign_in_and_redirect @user, :event => :authentication
else
flash[:notice] = "authentication error"
redirect_to root_path
end
end
def passthru
super
end
end
devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", user_omniauth_authorize_path(resource_name, provider:provider) %><br />
<% end -%>
<% end -%>
Answer the question
In order to leave comments, you need to log in
Searching for quite a few answers on this issue. None fit?
Where they write that a restart must be done, where - that this is an omniaus legacy.
It seems that everything is correct, but:
1. What is the link localhost:8080/users/auth/vkontakte.user ? It usually looks like localhost:8080/users/auth/vkontakte
2. Why does a user have attr_accessories?
3. Why are you identifying the user by a link, and not by a pair of provider + uid ? People love to change nicknames
4. Is that a typo?
provider is passed as a parameter, not as part of the hash. I copied this from my working project:
link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question