当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails - Help Using Devise with the built-in Omniauth Support

问题描述:

I tried to follow https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview, but somehow when I look at the generated routes I only see the callback path, and not the authorization path (and indeed I get the error on the view with the user_omniauth_authorize_path link).

I assume it might be a versions issue of OmniAuth and Devise (since after 0.2.0.beta Omniath allows configurable setting, and the routes must be defined). However, when trying to use an older OmniAuth version I get the error "You are using an old OmniAuth version, please ensure 0.2.0.beta or later installed.".

I tried working with Devise's master, 1.2.rc and the the omniauth branch and with both the entire omniauth gem (after 0.2.0.beta) and with 'oa-oauth' but without success.

I also tried to define the route:

match '/users/auth/:action/', :to => 'users/omniauth_callbacks#action', :as => 'user_omniauth_authorize'

This helped with the route, but when pressing the link I did get the error that devise cannot find a mapping. Funny enough, changing the controller in the devise_for to be invalid (like adding '/' before the users/omniauth_callbacks) resulted in an error the first time ("Controller name should not start with a slash"), but a small reload actually sent me to facebook and back (but naturally the callback route was not defined).

I am new to Ruby, and not quite sure where I go from here. Any help will be appreciated.

网友答案:

This method is defined by devise, not through routes. Therefore it will not show up when you run rake routes. The method takes one of the oauth providers that you have configured in config/initializers/devies.rb. For example if you define the following in devise.rb:

config.omniauth :facebook, FACEBOOK_APP_ID, FACEBOOK_APP_SECRET

Then you should build the authorize link like this:

<%= link_to "Facebook Sign in", user_omniauth_authorize_path(:facebook) %>
网友答案:

My problem was due to different versions of omniauth and devise. What finally worked was using this configuration in my gemfile:

gem 'devise', :git => 'git://github.com/plataformatec/devise.git'
gem 'omniauth', '>=0.2.0.beta'
gem 'oa-oauth', :require => 'omniauth/oauth'

you can see more details about my implementation here.

分享给朋友:
您可能感兴趣的文章:
随机阅读: