oauth-simple 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/History.txt +3 -0
- data/Manifest.txt +14 -0
- data/README.txt +48 -0
- data/Rakefile +28 -0
- data/TODO +24 -0
- data/lib/oauth-simple.rb +43 -0
- data/lib/oauth-simple/consumer.rb +91 -0
- data/lib/oauth-simple/http_client.rb +31 -0
- data/lib/oauth-simple/request.rb +138 -0
- data/lib/oauth-simple/signature_method.rb +31 -0
- data/lib/oauth-simple/signature_method_hmac_sha1.rb +54 -0
- data/lib/oauth-simple/signature_method_plaintext.rb +41 -0
- data/lib/oauth-simple/token.rb +58 -0
- data/lib/oauth-simple/version.rb +24 -0
- data/test/test_compat_regression.rb +105 -0
- data/test/test_consumer.rb +44 -0
- data/test/test_helper.rb +10 -0
- data/test/test_request.rb +46 -0
- data/test/test_signature_methods.rb +28 -0
- data/test/test_token.rb +24 -0
- metadata +104 -0
- metadata.gz.sig +1 -0
data.tar.gz.sig
ADDED
Binary file
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
History.txt
|
2
|
+
README.txt
|
3
|
+
Manifest.txt
|
4
|
+
Rakefile
|
5
|
+
TODO
|
6
|
+
lib/oauth-simple.rb
|
7
|
+
lib/oauth-simple/consumer.rb
|
8
|
+
lib/oauth-simple/http_client.rb
|
9
|
+
lib/oauth-simple/request.rb
|
10
|
+
lib/oauth-simple/signature_method.rb
|
11
|
+
lib/oauth-simple/signature_method_hmac_sha1.rb
|
12
|
+
lib/oauth-simple/signature_method_plaintext.rb
|
13
|
+
lib/oauth-simple/token.rb
|
14
|
+
lib/oauth-simple/version.rb
|
data/README.txt
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= oauth-simple
|
2
|
+
|
3
|
+
* FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
oauth-simple is a simpler OAuth implementation for Ruby, based on the Python version (http://oauth.googlecode.com/svn/code/python/oauth/)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Only consumers are supported
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* ruby-hmac if on before 1.9
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* sudo gem install oauth-simple
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2009 FIX
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require 'hoe'
|
3
|
+
require 'lib/oauth-simple'
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.test_files = FileList['test/test*.rb']
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
task :clobber_package do
|
11
|
+
`rm -fr pkg/*`
|
12
|
+
end
|
13
|
+
|
14
|
+
Hoe.new('oauth-simple', OAuthSimple::VERSION) do |h|
|
15
|
+
h.author = ['Marius Mathiesen']
|
16
|
+
h.email = 'marius.mathiesen@gmail.com'
|
17
|
+
h.description = 'Simple OAuth implementation'
|
18
|
+
h.summary = h.description
|
19
|
+
h.rubyforge_name = h.name
|
20
|
+
h.url = 'http://oauth-simple.rubyforge.org/'
|
21
|
+
if RUBY_VERSION < '1.9'
|
22
|
+
h.extra_deps << [
|
23
|
+
['ruby-hmac', '>= 0.3.1']
|
24
|
+
]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
task :default => [:test]
|
data/TODO
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Reality check:
|
2
|
+
✓ hente ut access token
|
3
|
+
✓ hente url fra denne
|
4
|
+
✓ besøke urlen
|
5
|
+
✓ hente access key
|
6
|
+
|
7
|
+
|
8
|
+
Next step:
|
9
|
+
✓ teste signature base string sammenlignet online suites
|
10
|
+
✓ Move into namespace
|
11
|
+
✓ Teste med forskjellige siter:
|
12
|
+
✓ agree2.com
|
13
|
+
✓ plone
|
14
|
+
✓ twitter
|
15
|
+
✓ Finne ut av hvordan å støtte porter
|
16
|
+
✓ Ruby 1.8
|
17
|
+
✓ Move CGI.escape into module method
|
18
|
+
✓ støtte for andre signeringsalgoritmer
|
19
|
+
- støtte for schemes
|
20
|
+
- flytte http-stash inn på riktig sted, respektere scheme
|
21
|
+
- samme API som for oauth-gemmen
|
22
|
+
✓ registrere prosjekt på Rubyforge
|
23
|
+
- sjekke ut støtte for asynk http (hvordan skal vi i det hele tatt gjøre dette?)
|
24
|
+
- Legge ut på Rubyforge
|
data/lib/oauth-simple.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009 Marius Mathiesen <marius.mathiesen@gmail.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
require 'cgi'
|
23
|
+
require 'uri'
|
24
|
+
require 'openssl'
|
25
|
+
$:.unshift(File.dirname(__FILE__))
|
26
|
+
if RUBY_VERSION <= "1.9"
|
27
|
+
require 'rubygems'
|
28
|
+
require 'hmac'
|
29
|
+
require 'hmac-sha1'
|
30
|
+
else
|
31
|
+
require 'digest/hmac'
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'oauth-simple/version'
|
35
|
+
require 'oauth-simple/consumer'
|
36
|
+
require 'oauth-simple/request'
|
37
|
+
require 'oauth-simple/http_client'
|
38
|
+
require 'oauth-simple/token'
|
39
|
+
require 'oauth-simple/signature_method'
|
40
|
+
require 'oauth-simple/signature_method_hmac_sha1'
|
41
|
+
require 'oauth-simple/signature_method_plaintext'
|
42
|
+
|
43
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009 Marius Mathiesen <marius.mathiesen@gmail.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
module OAuthSimple
|
23
|
+
class Consumer
|
24
|
+
attr_reader :key, :secret
|
25
|
+
def initialize(key, secret, options = {})
|
26
|
+
@key = key
|
27
|
+
@secret = secret
|
28
|
+
@options = self.class.default_options.merge(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Default options, can be overridden in the initializer's options hash
|
32
|
+
def self.default_options
|
33
|
+
{
|
34
|
+
:scheme => :header,
|
35
|
+
:authorize_path => '/oauth/authorize',
|
36
|
+
:access_token_path => '/oauth/access_token',
|
37
|
+
:request_token_path => '/oauth/request_token',
|
38
|
+
:signature_method => 'HMAC-SHA1'
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def site
|
43
|
+
@options[:site]
|
44
|
+
end
|
45
|
+
|
46
|
+
def scheme
|
47
|
+
@options[:scheme]
|
48
|
+
end
|
49
|
+
|
50
|
+
def authorize_path
|
51
|
+
@options[:authorize_path]
|
52
|
+
end
|
53
|
+
|
54
|
+
def access_token_path
|
55
|
+
@options[:access_token_path]
|
56
|
+
end
|
57
|
+
|
58
|
+
def request_token_path
|
59
|
+
@options[:request_token_path]
|
60
|
+
end
|
61
|
+
|
62
|
+
def http
|
63
|
+
HttpClient.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def signature_method
|
67
|
+
SignatureMethod.by_name(@options[:signature_method])
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_request_token
|
71
|
+
r = Request.from_consumer_and_token(self, nil, request_token_url)
|
72
|
+
r.sign_request(signature_method)
|
73
|
+
response = http.get(request_token_url, r.to_header)
|
74
|
+
result = Token.from_string(response)
|
75
|
+
result.consumer = self
|
76
|
+
return result
|
77
|
+
end
|
78
|
+
|
79
|
+
def request_token_url
|
80
|
+
@options[:request_token_url] || File.join(site, request_token_path)
|
81
|
+
end
|
82
|
+
|
83
|
+
def access_token_url
|
84
|
+
@options[:access_token_url] || File.join(site, access_token_path)
|
85
|
+
end
|
86
|
+
|
87
|
+
def authorize_url
|
88
|
+
@options[:authorize_url] || File.join(site, authorize_path)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009 Marius Mathiesen <marius.mathiesen@gmail.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
# A simplistic client that performs HTTP operations
|
24
|
+
require 'open-uri'
|
25
|
+
module OAuthSimple
|
26
|
+
class HttpClient
|
27
|
+
def get(url, headers)
|
28
|
+
open(url, 'r', headers).read
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009 Marius Mathiesen <marius.mathiesen@gmail.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
module OAuthSimple
|
23
|
+
class Request
|
24
|
+
VERSION = "1.0"
|
25
|
+
attr_accessor :consumer
|
26
|
+
def initialize(options={})
|
27
|
+
@http_method = options[:http_method] || :GET
|
28
|
+
@http_url = options[:http_url]
|
29
|
+
@parameters = options[:parameters] || {}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Builds a request from a consumer and (optionally) a token
|
33
|
+
def self.from_consumer_and_token(consumer, token, url, options = {})
|
34
|
+
defaults = {
|
35
|
+
'oauth_consumer_key' => consumer.key,
|
36
|
+
'oauth_timestamp' => generate_timestamp,
|
37
|
+
'oauth_nonce' => generate_nonce,
|
38
|
+
'oauth_version' => VERSION
|
39
|
+
}
|
40
|
+
options.merge!(defaults)
|
41
|
+
instance = new(:http_url => url, :parameters => options)
|
42
|
+
instance.set_parameter('oauth_token', token.key) if token
|
43
|
+
instance.consumer = consumer
|
44
|
+
return instance
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def set_parameter(k, v)
|
49
|
+
@parameters[k] = v
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_parameter(k)
|
53
|
+
@parameters[k]
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_nonoauth_parameters
|
57
|
+
@parameters.reject{|k,v| k =~ /^oauth_.*/}
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_header(realm=nil)
|
61
|
+
auth_header = "OAuth "
|
62
|
+
pairs = []
|
63
|
+
pairs << "realm=#{realm}"
|
64
|
+
@parameters.sort.each do |k, v|
|
65
|
+
if k =~ /^oauth_/
|
66
|
+
pairs << "#{k}=#{CGI.escape(v)}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
auth_header << pairs.join(", ")
|
70
|
+
return {"Authorization" => auth_header}
|
71
|
+
end
|
72
|
+
|
73
|
+
def postdata_hash
|
74
|
+
result = {}
|
75
|
+
@parameters.sort.each do |k,v|
|
76
|
+
result[k] = v
|
77
|
+
end
|
78
|
+
result
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_postdata
|
82
|
+
result = []
|
83
|
+
@parameters.sort.each do |key, value|
|
84
|
+
result << "#{CGI.escape(key)}=#{CGI.escape(value)}"
|
85
|
+
end
|
86
|
+
return result.join("&")
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_url
|
90
|
+
return "#{get_normalized_http_url}?#{to_postdata}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def get_normalized_http_url
|
94
|
+
parts = URI.parse(@http_url)
|
95
|
+
if parts.port == 80
|
96
|
+
return "#{parts.scheme}://#{parts.host}#{parts.path}"
|
97
|
+
else
|
98
|
+
return "#{parts.scheme}://#{parts.host}:#{parts.port}#{parts.path}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_normalized_http_method
|
103
|
+
return @http_method.to_s.upcase
|
104
|
+
end
|
105
|
+
|
106
|
+
def get_normalized_parameters
|
107
|
+
@parameters.sort.map do |k, values|
|
108
|
+
if values.is_a?(Array)
|
109
|
+
# multiple values were provided for a single key
|
110
|
+
values.sort.collect do |v|
|
111
|
+
[CGI.escape(k),CGI.escape(v)] * "="
|
112
|
+
end
|
113
|
+
else
|
114
|
+
[CGI.escape(k),CGI.escape(values)] * "="
|
115
|
+
end
|
116
|
+
end * "&"
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.generate_timestamp
|
120
|
+
return Time.now.to_i.to_s
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.generate_nonce(size=32)
|
124
|
+
bytes = OpenSSL::Random.random_bytes(size)
|
125
|
+
[bytes].pack('m').gsub(/\W/,'')
|
126
|
+
end
|
127
|
+
|
128
|
+
def sign_request(signature_klass, token=nil)
|
129
|
+
raise "Consumer is nothing" if @consumer.nil?
|
130
|
+
set_parameter('oauth_signature_method', signature_klass.oauth_name)
|
131
|
+
set_parameter('oauth_signature', build_signature(signature_klass, token))
|
132
|
+
end
|
133
|
+
|
134
|
+
def build_signature(signature_klass, token=nil)
|
135
|
+
return signature_klass.build_signature(self, consumer, token)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009 Marius Mathiesen <marius.mathiesen@gmail.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
module OAuthSimple
|
23
|
+
class SignatureMethod
|
24
|
+
def self.by_name(name)
|
25
|
+
{
|
26
|
+
'HMAC-SHA1' => SignatureMethodHMACSHA1,
|
27
|
+
'PLAINTEXT' => SignatureMethodPlaintext
|
28
|
+
}[name.to_s]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009 Marius Mathiesen <marius.mathiesen@gmail.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
module OAuthSimple
|
23
|
+
class SignatureMethodHMACSHA1 < SignatureMethod
|
24
|
+
def self.oauth_name
|
25
|
+
"HMAC-SHA1"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.build_signature_base_string(request, consumer, token)
|
29
|
+
sig = [
|
30
|
+
CGI.escape(request.get_normalized_http_method),
|
31
|
+
CGI.escape(request.get_normalized_http_url),
|
32
|
+
CGI.escape(request.get_normalized_parameters)
|
33
|
+
]
|
34
|
+
key = "#{CGI.escape(consumer.secret)}&"
|
35
|
+
key << CGI.escape(token.secret) if token
|
36
|
+
raw = sig.join("&")
|
37
|
+
return [key, raw]
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.build_signature(request, consumer, token)
|
41
|
+
key, raw = build_signature_base_string(request, consumer, token)
|
42
|
+
hashed = calculate_digest(key, raw)
|
43
|
+
return [hashed].pack('m').chomp.gsub(/\n/, '')
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.calculate_digest(key, data)
|
47
|
+
if RUBY_VERSION >= "1.9"
|
48
|
+
Digest::HMAC.new(key, Digest::SHA1).digest(data)
|
49
|
+
else
|
50
|
+
::HMAC::SHA1.digest(key, data)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009 Marius Mathiesen <marius.mathiesen@gmail.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
module OAuthSimple
|
23
|
+
class SignatureMethodPlaintext < SignatureMethod
|
24
|
+
|
25
|
+
def self.oauth_name
|
26
|
+
"PLAINTEXT"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.build_signature_base_string(request, consumer, token)
|
30
|
+
sig = "#{CGI.escape(consumer.secret)}&"
|
31
|
+
sig << CGI.escape(token.secret) if token
|
32
|
+
[sig, sig]
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.build_signature(request, consumer, token)
|
36
|
+
key, raw = build_signature_base_string(request, consumer, token)
|
37
|
+
return key
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009 Marius Mathiesen <marius.mathiesen@gmail.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
module OAuthSimple
|
23
|
+
class Token
|
24
|
+
attr_reader :key, :secret
|
25
|
+
def initialize(key, secret)
|
26
|
+
@key = key
|
27
|
+
@secret = secret
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
"oauth_token=#{CGI.escape(@key)}&oauth_token_secret=#{CGI.escape(@secret)}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.from_string(str)
|
35
|
+
params = CGI.parse(str)
|
36
|
+
return new(params['oauth_token'].first, params['oauth_token_secret'].first)
|
37
|
+
end
|
38
|
+
|
39
|
+
# In order to have a token generate a URL, it needs to know of its consumer.
|
40
|
+
# Doesn't look quite right to have it here, but the way the API works...
|
41
|
+
def consumer=(c)
|
42
|
+
@consumer = c
|
43
|
+
end
|
44
|
+
|
45
|
+
def authorize_url
|
46
|
+
req = Request.from_consumer_and_token(@consumer, self, @consumer.authorize_url, {})
|
47
|
+
return req.to_url
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_access_token
|
51
|
+
request = Request.from_consumer_and_token(@consumer, self, @consumer.access_token_url)
|
52
|
+
request.consumer = @consumer
|
53
|
+
request.sign_request(@consumer.signature_method, self)
|
54
|
+
response = open(request.get_normalized_http_url, 'r', request.to_header).read
|
55
|
+
return Token.from_string(response)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009 Marius Mathiesen <marius.mathiesen@gmail.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
module OAuthSimple
|
23
|
+
VERSION = '0.0.1'
|
24
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
class CompatRegressionTest < Test::Unit::TestCase
|
3
|
+
def setup
|
4
|
+
OAuthSimple::Request.stubs(:generate_nonce).returns("225579211881198842005988698334675835446")
|
5
|
+
OAuthSimple::Request.stubs(:generate_timestamp).returns("1199645624")
|
6
|
+
@consumer = OAuthSimple::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237',
|
7
|
+
:site => 'http://blabla.bla',
|
8
|
+
:scheme => :header,
|
9
|
+
:request_token_path => '/oauth/example/request_token.php',
|
10
|
+
:access_token_path => '/oauth/example/access_token.php',
|
11
|
+
:authorize_path => '/oauth/example/authorize.php'
|
12
|
+
)
|
13
|
+
@request = OAuthSimple::Request.new(
|
14
|
+
:http_method => :GET,
|
15
|
+
:parameters => {})
|
16
|
+
@token = OAuthSimple::Token.new('token_411a7f', '3196ffd991c8ebdb')
|
17
|
+
@request_uri = URI.parse('http://example.com/test?key=value')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_initializer
|
21
|
+
assert_equal 'consumer_key_86cad9', @consumer.key
|
22
|
+
assert_equal '5888bf0345e5d237', @consumer.secret
|
23
|
+
assert_equal 'http://blabla.bla', @consumer.site
|
24
|
+
assert_equal "/oauth/example/request_token.php",@consumer.request_token_path
|
25
|
+
assert_equal "/oauth/example/access_token.php",@consumer.access_token_path
|
26
|
+
assert_equal "http://blabla.bla/oauth/example/request_token.php",@consumer.request_token_url
|
27
|
+
assert_equal "http://blabla.bla/oauth/example/access_token.php",@consumer.access_token_url
|
28
|
+
assert_equal "http://blabla.bla/oauth/example/authorize.php",@consumer.authorize_url
|
29
|
+
assert_equal :header,@consumer.scheme
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_defaults
|
33
|
+
@consumer=OAuthSimple::Consumer.new(
|
34
|
+
"key",
|
35
|
+
"secret",
|
36
|
+
{
|
37
|
+
:site=>"http://twitter.com"
|
38
|
+
})
|
39
|
+
assert_equal "key",@consumer.key
|
40
|
+
assert_equal "secret",@consumer.secret
|
41
|
+
assert_equal "http://twitter.com",@consumer.site
|
42
|
+
assert_equal "/oauth/request_token",@consumer.request_token_path
|
43
|
+
assert_equal "/oauth/access_token",@consumer.access_token_path
|
44
|
+
assert_equal "http://twitter.com/oauth/request_token",@consumer.request_token_url
|
45
|
+
assert_equal "http://twitter.com/oauth/access_token",@consumer.access_token_url
|
46
|
+
assert_equal "http://twitter.com/oauth/authorize",@consumer.authorize_url
|
47
|
+
assert_equal :header,@consumer.scheme
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_override_paths
|
51
|
+
@consumer=OAuthSimple::Consumer.new(
|
52
|
+
"key",
|
53
|
+
"secret",
|
54
|
+
{
|
55
|
+
:site=>"http://twitter.com",
|
56
|
+
:request_token_url=>"http://oauth.twitter.com/request_token",
|
57
|
+
:access_token_url=>"http://oauth.twitter.com/access_token",
|
58
|
+
:authorize_url=>"http://site.twitter.com/authorize"
|
59
|
+
})
|
60
|
+
assert_equal "key",@consumer.key
|
61
|
+
assert_equal "secret",@consumer.secret
|
62
|
+
assert_equal "http://twitter.com",@consumer.site
|
63
|
+
assert_equal "/oauth/request_token",@consumer.request_token_path
|
64
|
+
assert_equal "/oauth/access_token",@consumer.access_token_path
|
65
|
+
assert_equal "http://oauth.twitter.com/request_token",@consumer.request_token_url
|
66
|
+
assert_equal "http://oauth.twitter.com/access_token",@consumer.access_token_url
|
67
|
+
assert_equal "http://site.twitter.com/authorize",@consumer.authorize_url
|
68
|
+
assert_equal :header,@consumer.scheme
|
69
|
+
end
|
70
|
+
|
71
|
+
# http://developer.netflix.com/resources/OAuthTest
|
72
|
+
def test_google_regressions_without_parameters
|
73
|
+
OAuthSimple::Request.stubs(:generate_nonce).returns("nonce")
|
74
|
+
OAuthSimple::Request.stubs(:generate_timestamp).returns("12345")
|
75
|
+
@consumer = OAuthSimple::Consumer.new('key', 'secret')
|
76
|
+
@token = OAuthSimple::Token.new('foo', 'bar')
|
77
|
+
@request = OAuthSimple::Request.from_consumer_and_token(@consumer, @token, 'http://oauth.example.com/do_oauth')
|
78
|
+
@request.sign_request(@consumer.signature_method, @token)
|
79
|
+
assert_equal 'http://oauth.example.com/do_oauth?oauth_consumer_key=key&oauth_nonce=nonce&oauth_signature=WZIO8HdSZy%2B6PKEkgrB8ZyqykT8%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12345&oauth_token=foo&oauth_version=1.0', @request.to_url
|
80
|
+
end
|
81
|
+
|
82
|
+
# http://developer.netflix.com/resources/OAuthTest
|
83
|
+
def test_google_regressions_with_parameters
|
84
|
+
OAuthSimple::Request.stubs(:generate_nonce).returns("nonce")
|
85
|
+
OAuthSimple::Request.stubs(:generate_timestamp).returns("12345")
|
86
|
+
@consumer = OAuthSimple::Consumer.new('key', 'secret')
|
87
|
+
@token = OAuthSimple::Token.new('foo', 'bar')
|
88
|
+
@request = OAuthSimple::Request.from_consumer_and_token(@consumer, @token, 'http://oauth.example.com/do_oauth', {'foo' => 'bar'})
|
89
|
+
@request.sign_request(@consumer.signature_method, @token)
|
90
|
+
assert_equal 'http://oauth.example.com/do_oauth?foo=bar&oauth_consumer_key=key&oauth_nonce=nonce&oauth_signature=xNxW8DDE4TXvTg9cXul7mSfDKeQ%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12345&oauth_token=foo&oauth_version=1.0', @request.to_url
|
91
|
+
end
|
92
|
+
|
93
|
+
# http://developer.netflix.com/resources/OAuthTest
|
94
|
+
def test_signature_generation_plaintext
|
95
|
+
OAuthSimple::Request.stubs(:generate_nonce).returns("nonce")
|
96
|
+
OAuthSimple::Request.stubs(:generate_timestamp).returns("12345")
|
97
|
+
@consumer = OAuthSimple::Consumer.new('key', 'secret', :signature_method => 'PLAINTEXT')
|
98
|
+
@token = OAuthSimple::Token.new('foo', 'bar')
|
99
|
+
@request = OAuthSimple::Request.from_consumer_and_token(@consumer, @token, 'http://oauth.example.com/do_oauth', {'foo' => 'bar'})
|
100
|
+
@request.sign_request(@consumer.signature_method, @token)
|
101
|
+
assert_equal 'secret&bar', @request.get_parameter('oauth_signature')
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
class ConsumerTest < Test::Unit::TestCase
|
3
|
+
def setup
|
4
|
+
OAuthSimple::Request.stubs(:generate_nonce).returns("nonce")
|
5
|
+
OAuthSimple::Request.stubs(:generate_timestamp).returns("12345")
|
6
|
+
@consumer = OAuthSimple::Consumer.new('key', 'secret', :site => 'http://localhost:3001/', :scheme => :header)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_basic_setup
|
10
|
+
consumer = OAuthSimple::Consumer.new('key', 'secret')
|
11
|
+
assert_equal 'key', consumer.key
|
12
|
+
assert_equal 'secret', consumer.secret
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_default_signature_method
|
16
|
+
@consumer = OAuthSimple::Consumer.new('key', 'secret')
|
17
|
+
assert_equal OAuthSimple::SignatureMethodHMACSHA1, @consumer.signature_method
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_setup_with_options
|
21
|
+
assert_equal 'http://localhost:3001/', @consumer.site
|
22
|
+
assert_equal :header, @consumer.scheme
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_customizable_paths
|
26
|
+
consumer = OAuthSimple::Consumer.new('key', 'secret',
|
27
|
+
:site => 'http://oauth.example',
|
28
|
+
:request_token_path => '/oauth/example/req.php',
|
29
|
+
:access_token_path => '/oauth/example/token.php',
|
30
|
+
:authorize_path => '/oauth/example/auth.php')
|
31
|
+
assert_equal '/oauth/example/req.php', consumer.request_token_path
|
32
|
+
assert_equal '/oauth/example/token.php', consumer.access_token_path
|
33
|
+
assert_equal '/oauth/example/auth.php', consumer.authorize_path
|
34
|
+
assert_equal 'http://oauth.example/oauth/example/req.php', consumer.request_token_url
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_aquire_request_token
|
38
|
+
http_request = mock('HTTP request')
|
39
|
+
http_request.expects(:get).with('http://localhost:3001/oauth/request_token', {'Authorization' => 'OAuth realm=, oauth_consumer_key=key, oauth_nonce=nonce, oauth_signature=eff4QrcF%2BzToX7GI4eHYsdc7wfo%3D, oauth_signature_method=HMAC-SHA1, oauth_timestamp=12345, oauth_version=1.0'}).returns('oauth_token=token&oauth_token_secret=top_secret')
|
40
|
+
@consumer.stubs(:http).returns(http_request)
|
41
|
+
token = @consumer.get_request_token
|
42
|
+
assert_kind_of OAuthSimple::Token, token
|
43
|
+
end
|
44
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class RequestTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@request = OAuthSimple::Request.new(:parameters => {'foo' => 'bar', 'oauth_bar' => 'baz', 'oauth_auth' => 'auth'},
|
6
|
+
:http_url => 'http://oauth.example.com/do_oauth')
|
7
|
+
@consumer = OAuthSimple::Consumer.new "key", "secret"
|
8
|
+
OAuthSimple::Request.stubs(:generate_nonce).returns("nonce")
|
9
|
+
OAuthSimple::Request.stubs(:generate_timestamp).returns("12345")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_non_oauth_parameters
|
13
|
+
assert_equal({'foo' => 'bar'}, @request.get_nonoauth_parameters)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_oauth_headers
|
17
|
+
assert_equal({'Authorization' => "OAuth realm=, oauth_auth=auth, oauth_bar=baz"}, @request.to_header)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_postdata
|
21
|
+
assert_equal("foo=bar&oauth_auth=auth&oauth_bar=baz", @request.to_postdata)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_normalized_http_url
|
25
|
+
assert_equal("http://oauth.example.com/do_oauth", @request.get_normalized_http_url)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_normalized_parameters
|
29
|
+
assert_equal("foo=bar&oauth_auth=auth&oauth_bar=baz", @request.get_normalized_parameters)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_sign_request_without_token
|
33
|
+
@request = OAuthSimple::Request.from_consumer_and_token(@consumer, nil, 'http://oauth.example.com/do_oauth',
|
34
|
+
'foo' => 'bar')
|
35
|
+
@request.sign_request(OAuthSimple::SignatureMethodHMACSHA1, nil)
|
36
|
+
assert_equal "w3FuykT3EmdgHZcSXINi8OhlG40=", @request.get_parameter("oauth_signature")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_generate_and_sign_access_token
|
40
|
+
access_token = OAuthSimple::Token.from_string("oauth_token=foo&oauth_token_secret=bar")
|
41
|
+
@request = OAuthSimple::Request.from_consumer_and_token(@consumer, nil, 'http://oauth.example.com/do_oauth')
|
42
|
+
@request.sign_request(OAuthSimple::SignatureMethodHMACSHA1, access_token)
|
43
|
+
assert_equal 'http://oauth.example.com/do_oauth?oauth_consumer_key=key&oauth_nonce=nonce&oauth_signature=loiAqloHcoLZAuvhxlt2nrOgXrM%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12345&oauth_version=1.0', @request.to_url
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009 Marius Mathiesen <marius.mathiesen@gmail.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
23
|
+
class SignatureMethodTest < Test::Unit::TestCase
|
24
|
+
def test_class_methods
|
25
|
+
assert_equal OAuthSimple::SignatureMethodHMACSHA1, OAuthSimple::SignatureMethod.by_name('HMAC-SHA1')
|
26
|
+
assert_equal OAuthSimple::SignatureMethodPlaintext, OAuthSimple::SignatureMethod.by_name('PLAINTEXT')
|
27
|
+
end
|
28
|
+
end
|
data/test/test_token.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class TokenTest < Test::Unit::TestCase
|
4
|
+
def test_to_s
|
5
|
+
t = OAuthSimple::Token.new("key", "secret")
|
6
|
+
assert_equal("oauth_token=key&oauth_token_secret=secret", t.to_s)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_parse_from_string
|
10
|
+
t = OAuthSimple::Token.from_string("oauth_token=key&oauth_token_secret=secret")
|
11
|
+
assert_equal("key", t.key)
|
12
|
+
assert_equal("secret", t.secret)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_authorize_url
|
16
|
+
OAuthSimple::Request.stubs(:generate_nonce).returns("nonce")
|
17
|
+
OAuthSimple::Request.stubs(:generate_timestamp).returns("12345")
|
18
|
+
consumer = OAuthSimple::Consumer.new('key', 'secret', :site => 'http://oauth.local/')
|
19
|
+
request_token = OAuthSimple::Token.from_string('oauth_token=key&oauth_token_secret=secret')
|
20
|
+
request_token.consumer = consumer
|
21
|
+
result = request_token.authorize_url
|
22
|
+
assert_equal 'http://oauth.local/oauth/authorize?oauth_consumer_key=key&oauth_nonce=nonce&oauth_timestamp=12345&oauth_token=key&oauth_version=1.0', result
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oauth-simple
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marius Mathiesen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDQjCCAiqgAwIBAgIBADANBgkqhkiG9w0BAQUFADBHMRkwFwYDVQQDDBBtYXJp
|
14
|
+
dXMubWF0aGllc2VuMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/Is
|
15
|
+
ZAEZFgNjb20wHhcNMDkwNDIzMTIyNTQ5WhcNMTAwNDIzMTIyNTQ5WjBHMRkwFwYD
|
16
|
+
VQQDDBBtYXJpdXMubWF0aGllc2VuMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzAR
|
17
|
+
BgoJkiaJk/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
|
18
|
+
AQCnTW1Sh+0Wef0+Ga4SOmFfVoCgDP9oBxuhA6FMr5tyt8a0Eh8U7aUOeFAYKdUV
|
19
|
+
hPz45QX8JG2qK9JKJCpS6Vw4+++3AelfYQjblN8DjKLQY6GUe8tJm67W4ZUBJpWQ
|
20
|
+
D6EQyNy3x9tOHqoV838J/nJcfajUobwiVktnJf160IsYko3sUAjMIqukX10BcbcY
|
21
|
+
V4vIWGBtBTpmLLzZIetIydvt2RgcDOxsdNEm75t8lszEmckpy0wvhq4MMlxqUUSO
|
22
|
+
uMUn9dOWIGWJyT3Y2aPoUV0h6phTt4dlUUQm05O8i1OkGUDzLJ6Y8Tb7czgR4zkG
|
23
|
+
RIhrMQFP5BA7joX1wmJQTrCfAgMBAAGjOTA3MAkGA1UdEwQCMAAwHQYDVR0OBBYE
|
24
|
+
FF0jJG1hKeH0OVGEzgbMWFgkq5PPMAsGA1UdDwQEAwIEsDANBgkqhkiG9w0BAQUF
|
25
|
+
AAOCAQEATd6h9TSGQehTVQmmguwbZAm19uMZnt4w6IJtV2MftRCUhBmOEiJ0Hqny
|
26
|
+
d3OxrfcUBtnCbnswvmYKyxhHkqUZnxT1cqRPg0OKDUuSTytZcUEcvm4Mvfwyqt/p
|
27
|
+
zlofbaegc0Or9HWT3Kg4C5lryrlEJe0D996bTObUHP/UAzBpAU6YRscQV9tk4MfF
|
28
|
+
6cG+4dZJ5GyqXY4cOQWmfLGJjotYRfy+3Ta4r0gOcM8iiOIHazvF+F+C1DN5AZfi
|
29
|
+
zNjcov+cRcmblc29PrBBZFAh2cnWKBwi5TFyGFq8b5fbjAEGS7NabyRybcppdrJo
|
30
|
+
2KP0QmP6AAwoAYED2ogaYVLyeyKh/A==
|
31
|
+
-----END CERTIFICATE-----
|
32
|
+
|
33
|
+
date: 2009-04-23 00:00:00 +02:00
|
34
|
+
default_executable:
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: hoe
|
38
|
+
type: :development
|
39
|
+
version_requirement:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.12.2
|
45
|
+
version:
|
46
|
+
description: Simple OAuth implementation
|
47
|
+
email: marius.mathiesen@gmail.com
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- History.txt
|
54
|
+
- README.txt
|
55
|
+
- Manifest.txt
|
56
|
+
files:
|
57
|
+
- History.txt
|
58
|
+
- README.txt
|
59
|
+
- Manifest.txt
|
60
|
+
- Rakefile
|
61
|
+
- TODO
|
62
|
+
- lib/oauth-simple.rb
|
63
|
+
- lib/oauth-simple/consumer.rb
|
64
|
+
- lib/oauth-simple/http_client.rb
|
65
|
+
- lib/oauth-simple/request.rb
|
66
|
+
- lib/oauth-simple/signature_method.rb
|
67
|
+
- lib/oauth-simple/signature_method_hmac_sha1.rb
|
68
|
+
- lib/oauth-simple/signature_method_plaintext.rb
|
69
|
+
- lib/oauth-simple/token.rb
|
70
|
+
- lib/oauth-simple/version.rb
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://oauth-simple.rubyforge.org/
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options:
|
75
|
+
- --main
|
76
|
+
- README.txt
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
version:
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project: oauth-simple
|
94
|
+
rubygems_version: 1.3.1
|
95
|
+
signing_key:
|
96
|
+
specification_version: 2
|
97
|
+
summary: Simple OAuth implementation
|
98
|
+
test_files:
|
99
|
+
- test/test_compat_regression.rb
|
100
|
+
- test/test_consumer.rb
|
101
|
+
- test/test_helper.rb
|
102
|
+
- test/test_request.rb
|
103
|
+
- test/test_signature_methods.rb
|
104
|
+
- test/test_token.rb
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
a�Į�y#qF��@�
|