在cutom omniauth策略中为getback_phase停止过滤器链

时间:2016-05-23 18:35:49

标签: ruby-on-rails omniauth

我正在尝试实现链接帐户的自定义策略,这是我的代码

 require 'omniauth-oauth2'
require 'multi_json'

module OmniAuth
  module Strategies
    class MyStrategy < OmniAuth::Strategies::OAuth2
      option :name, 'my_strategy'
      args [:consumer_key, :consumer_secret]
      option :consumer_key, nil
      option :consumer_secret, nil
      option :client_options, {
        site: SITE_URL,
        header: { ACCEPT_HEADERS },
        request_token_url: request_token_uri,
        access_token_url: access_token_uri,
        authorize_url: authorizerequest_token_uri
      }
      option :provider_ignores_state, true

      def consumer
        consumer = ::OAuth::Consumer.new(options.consumer_key, options.consumer_secret, options.client_options)
      end

      def request_phase
        binding.pry
        request_token = consumer.get_request_token({:oauth_callback => callback_url}, options.request_params)
        session["oauth"] ||= {}
        session["oauth"][name.to_s] = {"callback_confirmed" => request_token.callback_confirmed?, "request_token" => request_token.token, "request_secret" => request_token.secret}

        if request_token.callback_confirmed?
          redirect request_token.authorize_url(options[:authorize_params])
        else
          redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url))
        end

      rescue ::Timeout::Error => e
        fail!(:timeout, e)
      rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
        fail!(:service_unavailable, e)
      end

      def callback_phase
        binding.pry
      end

      def build_access_token
        binding.pry
        token_params = {
          :redirect_uri => callback_url.split('?').first,
          :client_id => client.id,
          :client_secret => client.secret
        }
        verifier = request.params['code']
        client.auth_code.get_token(verifier, token_params)
      end

      credentials do
        { "token" => access_token.token, "secret" => access_token.secret }
      end

      extra do
        { "access_token" => access_token }
      end

      def raw_info
        binding.pry
        @raw_info ||= access_token
      end
    end
  end
end

但我正在接到请求阶段的警告 过滤器链停止为:require_no_authentication呈现或重定向 因此,它进入无限循环(即它连续执行callback_phase)。

任何人都可以帮助说明为什么会这样,以及如何解决这个问题。

我正在使用rails 4。 谢谢

0 个答案:

没有答案