Sha256: 31b2dd76c3df7b079308e4ed508b9599bdc7b376831795de064a16965434e845

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

module Passport
  module Oauth
    module Context
      def self.included(base)
        base.extend ClassMethods
        base.send :include, InstanceMethods
      end
      
      module ClassMethods
        
        def provider
          find(:oauth_provider)
        end
        
        def token_class(throw_error = true)
          Passport.token(provider, throw_error)
        end
        
        def token_class?
          token_class(false).blank?
        end
        
        # the token from the response parameters
        def token
          version == 1.0 ? params_key(:oauth_token) : params_key(:code)
        end
        
        def request_token
          version == 1.0 ? session_key(:oauth_request_token) : nil
        end
        
        def request_secret
          version == 1.0 ? session_key(:oauth_request_token_secret) : params_key(:code)
        end
        
        def phase
          return "request" if request?
          return "response" if response?
          return "none"
        end

        def verifier
          params_key(:oauth_verifier)
        end

        # the version of oauth we're using.  Accessed from the OauthToken subclass
        def version
          token_class.version
        end
        
        # the Oauth gem consumer, whereby we can make requests to the server
        def consumer
          token_class.consumer
        end
        
        def callback_url(options = {})
          #"http://localhost:4567"
          Rack::Context.request.url.split("?").first
        end
        
        def inspect
          "#<Passport::Oauth::Protocol @version='#{version}' @token='#{token.inspect}' @phase='#{phase}'>"
        end
      end
      
      module InstanceMethods
        
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
passport-0.1.1 lib/passport/oauth/protocol/context.rb