oauth1 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/README.md +24 -1
- data/lib/oauth1/helper.rb +13 -7
- data/lib/oauth1/version.rb +1 -1
- data/spec/oauth1/helper_spec.rb +35 -35
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e1478cf15e24757ee13844ef6f016018b3b67d2
|
4
|
+
data.tar.gz: 92cb424fc754762c2cf415257f4147fe9d4ab7e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3de5d792698b6133079ec7687717474911a8c4711125ad466ea8af8e60dbd407d7a16883d0d2caeb3045dac0dd0782c3d80a51153f619542312ffed165d1ba57
|
7
|
+
data.tar.gz: a3c611a190c7e5f8df6964ee9e5abb0cfdaab4bed454e92f7424e82305cde7938d0ff3b6760c9dea0c57af6091dda9c99624241a133eec44abe50b1760ed2457
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/lunks/oauth1.svg?branch=master)](https://travis-ci.org/lunks/oauth1)
|
2
|
+
[![Dependency Status](https://gemnasium.com/lunks/oauth1.svg)](https://gemnasium.com/lunks/oauth1)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/lunks/oauth1/badges/gpa.svg)](https://codeclimate.com/github/lunks/oauth1)
|
4
|
+
|
1
5
|
# OAuth1
|
2
6
|
|
3
|
-
Simple
|
7
|
+
Simple helper that helps you build the url needed to authenticate into a service using OAuth 1.0.
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
@@ -16,6 +20,25 @@ Or install it yourself as:
|
|
16
20
|
|
17
21
|
$ gem install oauth1
|
18
22
|
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
# Setup data
|
26
|
+
method = :get
|
27
|
+
domain_url = 'http://some.app.com/auth/'
|
28
|
+
user_date = { uid: user_email + encrypted_password }
|
29
|
+
oauth_config = { consumer_key: ENV['OAUTH_KEY'], consumer_secret: ENV['OAUTH_SECRET'] }
|
30
|
+
|
31
|
+
# Usage
|
32
|
+
oauth = Oauth::Helper.new(method, domain_url, user_data, oauth_config)
|
33
|
+
|
34
|
+
# Returns
|
35
|
+
oauth.signature_base # Returns the signature appended in the auth url
|
36
|
+
oauth.full_url # The proper url used for authentication
|
37
|
+
|
38
|
+
|
39
|
+
After that, all you need to do is to redirect the user to `oauth.full_url`.
|
40
|
+
|
41
|
+
|
19
42
|
## Contributing
|
20
43
|
|
21
44
|
1. Fork it
|
data/lib/oauth1/helper.rb
CHANGED
@@ -3,6 +3,7 @@ require 'addressable/uri'
|
|
3
3
|
require 'cgi'
|
4
4
|
require 'base64'
|
5
5
|
require 'openssl'
|
6
|
+
require 'securerandom'
|
6
7
|
|
7
8
|
module OAuth1
|
8
9
|
class Helper
|
@@ -13,24 +14,21 @@ module OAuth1
|
|
13
14
|
version: "1.0",
|
14
15
|
signature_method: 'HMAC-SHA1',
|
15
16
|
timestamp: Time.now.to_i.to_s,
|
16
|
-
nonce: SecureRandom.uuid
|
17
|
-
token: ""
|
17
|
+
nonce: SecureRandom.uuid
|
18
18
|
})
|
19
19
|
|
20
20
|
@consumer_secret = options.delete(:consumer_secret)
|
21
|
+
@token_secret = options.delete(:token_secret)
|
21
22
|
@url_params = params.merge(prepend_oauth_to_key(options))
|
22
|
-
|
23
23
|
@method = method.to_s.upcase
|
24
24
|
@url = Addressable::URI.parse(url)
|
25
25
|
end
|
26
26
|
|
27
27
|
def signature_base
|
28
|
+
@url_params.delete(:oauth_signature)
|
28
29
|
[@method, @url.to_s, url_with_params.query].map{|v| CGI.escape(v) }.join('&')
|
29
30
|
end
|
30
31
|
|
31
|
-
def append_signature_to_params
|
32
|
-
@url_params[:oauth_signature] = hmac_sha1_signature("#{CGI.escape(@consumer_secret)}&", signature_base)
|
33
|
-
end
|
34
32
|
|
35
33
|
def full_url
|
36
34
|
append_signature_to_params
|
@@ -38,16 +36,24 @@ module OAuth1
|
|
38
36
|
end
|
39
37
|
|
40
38
|
private
|
39
|
+
def key
|
40
|
+
@token_secret ? "#{CGI.escape(@consumer_secret)}&#{CGI.escape(@token_secret)}" : "#{CGI.escape(@consumer_secret)}&"
|
41
|
+
end
|
42
|
+
|
41
43
|
def url_with_params
|
42
44
|
@url.dup.tap{|url| url.query_values = url_params}
|
43
45
|
end
|
44
46
|
|
47
|
+
def append_signature_to_params
|
48
|
+
@url_params[:oauth_signature] = hmac_sha1_signature(key, signature_base)
|
49
|
+
end
|
50
|
+
|
45
51
|
def prepend_oauth_to_key(options)
|
46
52
|
Hash[options.map{|key, value| ["oauth_#{key}".to_sym, value]}]
|
47
53
|
end
|
48
54
|
|
49
55
|
def hmac_sha1_signature(key, signature_string)
|
50
|
-
digest = OpenSSL::Digest
|
56
|
+
digest = OpenSSL::Digest.new('sha1')
|
51
57
|
hmac = OpenSSL::HMAC.digest(digest, key, signature_string)
|
52
58
|
Base64.encode64(hmac).chomp.gsub(/\n/, '')
|
53
59
|
end
|
data/lib/oauth1/version.rb
CHANGED
data/spec/oauth1/helper_spec.rb
CHANGED
@@ -1,66 +1,66 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe OAuth1::Helper do
|
4
|
-
let(:url) {
|
5
|
-
let(:params) { {
|
6
|
-
let(:consumer_key) {
|
7
|
-
let(:consumer_secret) {
|
4
|
+
let(:url) { 'http://example.com' }
|
5
|
+
let(:params) { {user_specified_param: 'params'} }
|
6
|
+
let(:consumer_key) { 'some_key' }
|
7
|
+
let(:consumer_secret) { 'some_secret' }
|
8
8
|
|
9
9
|
let(:helper) { OAuth1::Helper.new(:get, url, params, {consumer_key: consumer_key, consumer_secret: consumer_secret}) }
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe '#url_params' do
|
12
12
|
let(:url_params) { helper.url_params }
|
13
|
-
|
14
|
-
|
13
|
+
|
14
|
+
it 'prepends "oauth_" to option keys' do
|
15
|
+
expect(url_params.keys).to include(:oauth_consumer_key)
|
15
16
|
end
|
16
17
|
|
17
|
-
it
|
18
|
-
url_params.keys.
|
18
|
+
it 'has some default options' do
|
19
|
+
expect(url_params.keys).to include(:oauth_version)
|
19
20
|
end
|
20
21
|
|
21
|
-
it
|
22
|
-
url_params.keys.
|
22
|
+
it 'does not include the consumer_secret' do
|
23
|
+
expect(url_params.keys).to_not include('oauth_consumer_secret')
|
23
24
|
end
|
24
25
|
|
25
|
-
it
|
26
|
-
url_params[:oauth_token].
|
26
|
+
it 'does not have oauth_token as a param' do
|
27
|
+
expect(url_params[:oauth_token]).to be_nil
|
27
28
|
end
|
28
|
-
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
it "returns an array with the options and the params" do
|
33
|
-
url_params.should have(7).params
|
30
|
+
it 'returns an array with the options and the params' do
|
31
|
+
expect(url_params.keys).to have(6).items
|
34
32
|
end
|
35
33
|
|
36
|
-
it
|
37
|
-
url_params.keys.
|
34
|
+
it 'has any user specified params' do
|
35
|
+
expect(url_params.keys).to include(:user_specified_param)
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
41
|
-
describe
|
39
|
+
describe '#signature_base' do
|
42
40
|
let(:signature_base) { helper.signature_base }
|
43
|
-
|
44
|
-
|
41
|
+
|
42
|
+
it { expect(signature_base).to be_a(String) }
|
43
|
+
|
44
|
+
it 'contains the http method' do
|
45
|
+
expect(signature_base).to match(/GET/)
|
45
46
|
end
|
46
47
|
|
47
|
-
it
|
48
|
-
signature_base.
|
48
|
+
it 'contains the url' do
|
49
|
+
expect(signature_base).to match(/example.com/)
|
49
50
|
end
|
50
51
|
|
51
|
-
it
|
52
|
-
signature_base.
|
53
|
-
signature_base.
|
52
|
+
it 'contains the params' do
|
53
|
+
expect(signature_base).to match(/oauth_consumer_key/)
|
54
|
+
expect(signature_base).to match(/user_specified_param/)
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
|
-
describe
|
58
|
+
describe '#full_url' do
|
58
59
|
let(:full_url) { helper.full_url }
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
60
|
+
|
61
|
+
it { expect(full_url).to match(/oauth_consumer_key=#{consumer_key}/) }
|
62
|
+
it { expect(full_url).to match(/oauth_signature_method=HMAC-SHA1/) }
|
63
|
+
it { expect(full_url).to match(/oauth_signature=/) }
|
64
|
+
it { expect(full_url).to match(/user_specified_param/) }
|
65
65
|
end
|
66
66
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matheus Bras
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-07-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- .gitignore
|
93
93
|
- .ruby-gemset
|
94
94
|
- .ruby-version
|
95
|
+
- .travis.yml
|
95
96
|
- Gemfile
|
96
97
|
- LICENSE.txt
|
97
98
|
- README.md
|
@@ -122,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
123
|
version: '0'
|
123
124
|
requirements: []
|
124
125
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.0.
|
126
|
+
rubygems_version: 2.0.14
|
126
127
|
signing_key:
|
127
128
|
specification_version: 4
|
128
129
|
summary: In case you need to craft an OAuth 1.0 URL with HMAC-SHA1, this may be helpful.
|