oauth1 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/Rakefile +1 -0
- data/lib/oauth1.rb +5 -0
- data/lib/oauth1/helper.rb +55 -0
- data/lib/oauth1/version.rb +3 -0
- data/oauth1.gemspec +26 -0
- data/spec/oauth1/helper_spec.rb +66 -0
- data/spec/spec_helper.rb +8 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4ca906e79f1d51b69b98d0b74a942eeaa9ec5666
|
4
|
+
data.tar.gz: cd36870a23d68a0fc888c3a1ed55e4a551436dda
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb8b8819e07b01661fc2ab05a1865fb857e4580b0a9233bb63d79a17780b05bca59542987e7ad5d20210e8b1a7b768304875f4728b3b12981d972aa6c55aed43
|
7
|
+
data.tar.gz: cc6b1c07a31934fb4c741cad7a528c0cb3c1fad0de8a8455ab68f3cb9adbe07c5297e64ccee46b0545e633b0f67f86cd664351a242b3fc4c90f436a960e8d160
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
oauth1
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Matheus Bras
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# OAuth1
|
2
|
+
|
3
|
+
Simple OAuth 1.0 helper. Take a look at the specs on how to use it.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'oauth1'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install oauth1
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
1. Fork it
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/oauth1.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'active_support/core_ext/hash/reverse_merge'
|
2
|
+
require 'addressable/uri'
|
3
|
+
require 'cgi'
|
4
|
+
require 'base64'
|
5
|
+
require 'openssl'
|
6
|
+
|
7
|
+
module OAuth1
|
8
|
+
class Helper
|
9
|
+
attr_reader :url_params
|
10
|
+
|
11
|
+
def initialize(method, url, params, options)
|
12
|
+
options.reverse_update({
|
13
|
+
version: "1.0",
|
14
|
+
signature_method: 'HMAC-SHA1',
|
15
|
+
timestamp: Time.now.to_i.to_s,
|
16
|
+
nonce: SecureRandom.uuid,
|
17
|
+
token: ""
|
18
|
+
})
|
19
|
+
|
20
|
+
@consumer_secret = options.delete(:consumer_secret)
|
21
|
+
@url_params = params.merge(prepend_oauth_to_key(options))
|
22
|
+
|
23
|
+
@method = method.to_s.upcase
|
24
|
+
@url = Addressable::URI.parse(url)
|
25
|
+
end
|
26
|
+
|
27
|
+
def signature_base
|
28
|
+
[@method, @url.to_s, url_with_params.query].map{|v| CGI.escape(v) }.join('&')
|
29
|
+
end
|
30
|
+
|
31
|
+
def append_signature_to_params
|
32
|
+
@url_params[:oauth_signature] = hmac_sha1_signature("#{CGI.escape(@consumer_secret)}&", signature_base)
|
33
|
+
end
|
34
|
+
|
35
|
+
def full_url
|
36
|
+
append_signature_to_params
|
37
|
+
url_with_params.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def url_with_params
|
42
|
+
@url.dup.tap{|url| url.query_values = url_params}
|
43
|
+
end
|
44
|
+
|
45
|
+
def prepend_oauth_to_key(options)
|
46
|
+
Hash[options.map{|key, value| ["oauth_#{key}".to_sym, value]}]
|
47
|
+
end
|
48
|
+
|
49
|
+
def hmac_sha1_signature(key, signature_string)
|
50
|
+
digest = OpenSSL::Digest::Digest.new('sha1')
|
51
|
+
hmac = OpenSSL::HMAC.digest(digest, key, signature_string)
|
52
|
+
Base64.encode64(hmac).chomp.gsub(/\n/, '')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/oauth1.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'oauth1/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "oauth1"
|
8
|
+
spec.version = OAuth1::VERSION
|
9
|
+
spec.authors = ["Matheus Bras", "Pedro Nascimento"]
|
10
|
+
spec.email = ["matheus@helabs.com.br", "pedro@helabs.com.br"]
|
11
|
+
spec.description = %q{Simple OAuth 1.0 Helper to generate URLs with HMAC-SHA1 encoding.}
|
12
|
+
spec.summary = %q{In case you need to craft an OAuth 1.0 URL with HMAC-SHA1, this may be helpful.}
|
13
|
+
spec.homepage = "http://helabs.com.br/opensource"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.13.0"
|
24
|
+
spec.add_dependency "addressable"
|
25
|
+
spec.add_dependency "activesupport", "> 3.0.11"
|
26
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OAuth1::Helper do
|
4
|
+
let(:url) { "http://example.com" }
|
5
|
+
let(:params) { {my_special_param: "params"} }
|
6
|
+
let(:consumer_key) { "some_key" }
|
7
|
+
let(:consumer_secret) { "some_secret" }
|
8
|
+
|
9
|
+
let(:helper) { OAuth1::Helper.new(:get, url, params, {consumer_key: consumer_key, consumer_secret: consumer_secret}) }
|
10
|
+
|
11
|
+
describe "#url_params" do
|
12
|
+
let(:url_params) { helper.url_params }
|
13
|
+
it "prepends oauth_ to option keys" do
|
14
|
+
url_params.keys.should include(:oauth_consumer_key)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has some default options" do
|
18
|
+
url_params.keys.should include(:oauth_version)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "doesn't include the consumer_secret" do
|
22
|
+
url_params.keys.should_not include("oauth_consumer_secret")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has oauth_token as an empty string" do
|
26
|
+
url_params[:oauth_token].should eq("")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#url_params" do
|
31
|
+
let(:url_params) { helper.url_params }
|
32
|
+
it "returns an array with the options and the params" do
|
33
|
+
url_params.should have(7).params
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has the user-specified params" do
|
37
|
+
url_params.keys.should include(:my_special_param)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#signature_base" do
|
42
|
+
let(:signature_base) { helper.signature_base }
|
43
|
+
it "returns an escaped string with method" do
|
44
|
+
signature_base.should match(/GET/)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns an escaped string with url" do
|
48
|
+
signature_base.should match(/example.com/)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns an escaped string with the params" do
|
52
|
+
signature_base.should match(/oauth_consumer_key/)
|
53
|
+
signature_base.should match(/my_special_param/)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#full_url" do
|
58
|
+
let(:full_url) { helper.full_url }
|
59
|
+
it "returns the url with the params for auth" do
|
60
|
+
full_url.should match(/oauth_consumer_key=#{consumer_key}/)
|
61
|
+
full_url.should match(/oauth_signature_method=HMAC-SHA1/)
|
62
|
+
full_url.should match(/oauth_signature=/)
|
63
|
+
full_url.should match(/my_special_param/)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oauth1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matheus Bras
|
8
|
+
- Pedro Nascimento
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.13.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.13.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: addressable
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: activesupport
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>'
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 3.0.11
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>'
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 3.0.11
|
84
|
+
description: Simple OAuth 1.0 Helper to generate URLs with HMAC-SHA1 encoding.
|
85
|
+
email:
|
86
|
+
- matheus@helabs.com.br
|
87
|
+
- pedro@helabs.com.br
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- .ruby-gemset
|
94
|
+
- .ruby-version
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- lib/oauth1.rb
|
100
|
+
- lib/oauth1/helper.rb
|
101
|
+
- lib/oauth1/version.rb
|
102
|
+
- oauth1.gemspec
|
103
|
+
- spec/oauth1/helper_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
homepage: http://helabs.com.br/opensource
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.0.3
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: In case you need to craft an OAuth 1.0 URL with HMAC-SHA1, this may be helpful.
|
129
|
+
test_files:
|
130
|
+
- spec/oauth1/helper_spec.rb
|
131
|
+
- spec/spec_helper.rb
|