我正在从事Rails项目,但是omniauth-linkedin-oauth2
无法正常工作!我有如下错误。
Authentication failure! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected | CSRF detected
apps / controllers / omniauth_controller.rb
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user = User.from_omniauth(request.env["omniauth.auth"].except("extra"))
if @user.persisted?
sign_in_and_redirect @user, event: :authentication
else
session["devise.user_attributes"] = @user.attributes
redirect_to new_user_registration_url
end
end
def linkedin
@user = User.from_omniauth(request.env["omniauth.auth"].except("extra"))
if @user.persisted?
sign_in_and_redirect @user, event: :authentication
else
session["devise.user_attributes"] = @user.attributes
redirect_to new_user_registration_url
end
end
end
config / initializers / devise.rb
config.omniauth :linkedin,
Rails.application.credentials[Rails.env.to_sym][:linkedin][:client_id],
Rails.application.credentials[Rails.env.to_sym][:linkedin][:client_secret],
provider_ignores_state: true