Skip to content

Commit

Permalink
made spacing consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
mojodna committed Jan 28, 2009
1 parent ebd8fbe commit 6a03c0b
Show file tree
Hide file tree
Showing 18 changed files with 301 additions and 301 deletions.
12 changes: 5 additions & 7 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ As a matter of fact it has been pulled out from an OAuth Rails Plugin http://cod

Create a new consumer instance by passing it a configuration hash:

@consumer=OAuth::Consumer.new( "key","secret", {
:site=>"https://agree2"
})
@consumer = OAuth::Consumer.new("key","secret", :site => "https://agree2")

Start the process by requesting a token

@request_token=@consumer.get_request_token
session[:request_token]=@request_token
@request_token = @consumer.get_request_token
session[:request_token] = @request_token
redirect_to @request_token.authorize_url

When user returns create an access_token

@access_token=@request_token.get_access_token
@photos=@access_token.get('/photos.xml')
@access_token = @request_token.get_access_token
@photos = @access_token.get('/photos.xml')

For more detailed instructions I have written this OAuth Client Tutorial http://stakeventures.com/articles/2008/02/23/developing-oauth-clients-in-ruby and "How to turn your rails site into an OAuth Provider ":http://stakeventures.com/articles/2007/11/26/how-to-turn-your-rails-site-into-an-oauth-provider .

Expand Down
25 changes: 13 additions & 12 deletions lib/oauth/client/action_controller_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

module ActionController
class Base
def process_with_oauth(request,response=nil)
def process_with_oauth(request, response=nil)
request.apply_oauth!
process_without_oauth(request,response)
process_without_oauth(request, response)
end

alias_method_chain :process, :oauth
Expand All @@ -18,21 +18,22 @@ def self.use_oauth=(bool)
end

def self.use_oauth?
@use_oauth
@use_oauth
end

def configure_oauth(consumer = nil, token = nil, options = {})
@oauth_options = { :consumer => consumer,
:token => token,
:scheme => 'header',
:signature_method => nil,
:nonce => nil,
:timestamp => nil }.merge(options)
@oauth_options = { :consumer => consumer,
:token => token,
:scheme => 'header',
:signature_method => nil,
:nonce => nil,
:timestamp => nil }.merge(options)
end

def apply_oauth!
return unless ActionController::TestRequest.use_oauth? && @oauth_options
@oauth_helper = OAuth::Client::Helper.new(self, @oauth_options.merge( { :request_uri => request_uri } ))

@oauth_helper = OAuth::Client::Helper.new(self, @oauth_options.merge(:request_uri => request_uri))

self.send("set_oauth_#{@oauth_options[:scheme]}")
end
Expand All @@ -43,9 +44,9 @@ def set_oauth_header

def set_oauth_parameters
@query_parameters = @oauth_helper.parameters_with_oauth
@query_parameters.merge!( { :oauth_signature => @oauth_helper.signature } )
@query_parameters.merge!(:oauth_signature => @oauth_helper.signature)
end

def set_oauth_query_string
end
end
Expand Down
18 changes: 9 additions & 9 deletions lib/oauth/client/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module OAuth::Client
class Helper
include OAuth::Helper

def initialize(request, options = {})
@request = request
@options = options
Expand Down Expand Up @@ -43,20 +43,20 @@ def oauth_parameters

def signature(extra_options = {})
OAuth::Signature.sign(@request, { :uri => options[:request_uri],
:consumer => options[:consumer],
:token => options[:token] }.merge(extra_options) )
:consumer => options[:consumer],
:token => options[:token] }.merge(extra_options) )
end

def signature_base_string(extra_options = {})
OAuth::Signature.signature_base_string(@request, { :uri => options[:request_uri],
:consumer => options[:consumer],
:token => options[:token],
:parameters => oauth_parameters}.merge(extra_options) )
OAuth::Signature.signature_base_string(@request, { :uri => options[:request_uri],
:consumer => options[:consumer],
:token => options[:token],
:parameters => oauth_parameters}.merge(extra_options) )
end

def header
parameters = oauth_parameters
parameters.merge!( { 'oauth_signature' => signature( options.merge({ :parameters => parameters }) ) } )
parameters.merge!('oauth_signature' => signature(options.merge(:parameters => parameters)))

header_params_str = parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ')

Expand All @@ -69,7 +69,7 @@ def parameters
end

def parameters_with_oauth
oauth_parameters.merge( parameters )
oauth_parameters.merge(parameters)
end
end
end
37 changes: 21 additions & 16 deletions lib/oauth/client/net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,47 @@ class Net::HTTPRequest
include OAuth::Helper

def oauth!(http, consumer = nil, token = nil, options = {})
options = { :request_uri => oauth_full_request_uri(http),
:consumer => consumer,
:token => token,
:scheme => 'header',
options = { :request_uri => oauth_full_request_uri(http),
:consumer => consumer,
:token => token,
:scheme => 'header',
:signature_method => nil,
:nonce => nil,
:timestamp => nil }.merge(options)
:nonce => nil,
:timestamp => nil }.merge(options)

@oauth_helper = OAuth::Client::Helper.new(self, options)
self.send("set_oauth_#{options[:scheme]}")
end

def signature_base_string(http, consumer = nil, token = nil, options = {})
options = { :request_uri => oauth_full_request_uri(http),
:consumer => consumer,
:token => token,
:scheme => 'header',
options = { :request_uri => oauth_full_request_uri(http),
:consumer => consumer,
:token => token,
:scheme => 'header',
:signature_method => nil,
:nonce => nil,
:timestamp => nil }.merge(options)
:nonce => nil,
:timestamp => nil }.merge(options)

OAuth::Client::Helper.new(self, options).signature_base_string
end

def oauth_helper
@oauth_helper
end
private

private

def oauth_full_request_uri(http)
uri = URI.parse(self.path)
uri.host = http.address
uri.port = http.port
if http.respond_to?(:use_ssl?)
uri.scheme = http.use_ssl? ? 'https' : 'http'

if http.respond_to?(:use_ssl?) && http.use_ssl?
uri.scheme = "https"
else
uri.scheme = "http"
end

uri.to_s
end

Expand Down
Loading

0 comments on commit 6a03c0b

Please sign in to comment.