Devise Omniauth控制器呈现404

时间:2013-04-02 20:41:49

标签: devise omniauth

第一种情况

控制器

class Api::V1::AuthsController < Devise::OmniauthCallbacksController
  def twitter; end

  private

  def callback
    user = User.find_or_authenticate_by_oauth(request.env["omniauth.auth"], session['beta_signup_token'])

    if session['beta_signup_token'] 
      render json: {redirect: :complete_profile}
    else
      render json: {redirect: :stories}
    end
  end
end

路线

  namespace :api do
    namespace :v1 do
      devise_scope :user do
        match 'auth/:provider' => 'auths#passthru', constraints: { format: :json }
        match 'auth/:provider/callback', to: 'auths#callback', constraints: { format: :json }
      end
    end
  end

响应

Started GET "/api/v1/auth/twitter.json" for 127.0.0.1 at 2013-04-02 14:43:32 -0500
Processing by Api::V1::AuthsController#passthru as JSON
  Parameters: {"provider"=>"twitter"}
  Rendered text template (0.0ms)
Completed 404 Not Found in 4ms (Views: 0.5ms | ActiveRecord: 0.0ms)

第二种情况

控制器

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  before_filter :handle_authentication

  def facebook
  end

  def twitter
  end

  def linkedin
  end

  private

  def handle_authentication
    user = User.find_or_authenticate_by_oauth(request.env["omniauth.auth"],  session['beta_signup_token'])

    if session['beta_signup_token'] 
      redirect_to setup_profile_beta_invite_url(session['beta_signup_token'])
    else
      sign_in_and_redirect
    end
  end
end

路线

devise_for :users, constraints: { format: :html },
  :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

响应

(twitter) Callback phase initiated.

Started GET "/users/auth/twitter" for 127.0.0.1 at 2013-04-02 15:40:04 -0500

我的问题

如何使第一个响应与第二个响应相同?我想在第一个,Twitter策略没有被调用,为什么?

我认为我的其他question是相关的

0 个答案:

没有答案