我试图弄清楚如何使用Rails 4应用程序配置LinkedIn的身份验证,该应用程序使用devise和omniauth。我的gem文件中有gem'omniauth-linkedin-oauth2'。
我已经在LinkedIn上注册了我的应用程序,并在我的应用程序中插入了秘密和密钥。LinkedIn开发人员论坛已确认该过程正在运行,但表示注册的重定向路径与我在回调中的内容不匹配。
我有一个omniauth_callbacks控制器,其中包含以下代码:
def linkedin
@user = User.find_for_linkedin_oauth(request.env["omniauth.auth"])
if @user.persisted?
redirect_to root_path, :event => :authentication
# sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
# set_flash_message(:notice, :success, :kind => "LinkedIn") if is_navigational_format?
else
session["devise.linkedin_data"] = request.env["omniauth.auth"]
redirect_to root_path
end
end
我正在重定向到我的root_path。
我的root_path在我的route.rb文件中定义为:home#home。
在我的views文件夹中,我有一个名为home的文件夹,其中有一个名为home.html.erb的文件。
我已经在LinkedIn上将重定向URL注册为:www.xxxxxxx.com/home,并且还尝试了以下操作:www.xxxxxxx.com,www.xxxxxxx.com / views / home / home,www.xxxxxxx.com / home /家。这些路径均无效。
请有人帮助我了解如何定义重定向路径,LinkedIn可以将其重定向为匹配我的root_path的路径。
提前非常感谢您。
运行rake routes
并查看以URI模式结尾的内容callback
。
您很可能会找到类似的模式:
/users/auth/:action/callback(.:format)
这意味着在开发中,您的回调URL将为:
http://localhost:3000/users/auth/linkedin/callback
在生产中,您的回调网址将是:
www.xxxxxxx.com/users/auth/linkedin/callback
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句