oauth-one 0.0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47b5066e959f1429195527d60feeb8c6db507edd
4
+ data.tar.gz: d4911947fca093c308590c841b60b2f0bf66a29c
5
+ SHA512:
6
+ metadata.gz: a855e9e70c30d6c8ad654e4a6865ff0d88365f4fda52a384a41ce09bbe8dce60d6734e12e7dc285fd0e77f8ac471006e286d0f5e4fbd422c89946e0c211415b9
7
+ data.tar.gz: 11e6c527330ed69934371657716a2214a7c7e5a7d7c523b3a821e9b1ce18932665e13a0d8a3d0a4254f225ae3df477b8eabfed20f0d056d65603396e3ecae713
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ oauth-one
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.1
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 2.1.1
5
+ - 2.1.0
6
+ - 2.0.0
7
+ - 1.9.3
8
+ - jruby-19mode # JRuby in 1.9 mode
9
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in oauth_one.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ oauth-one (0.0.3)
5
+ activesupport (> 3.0.11)
6
+ addressable
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.6.0)
17
+ public_suffix (>= 2.0.2, < 4.0)
18
+ coderay (1.1.2)
19
+ concurrent-ruby (1.1.4)
20
+ diff-lcs (1.3)
21
+ i18n (1.5.2)
22
+ concurrent-ruby (~> 1.0)
23
+ method_source (0.9.2)
24
+ minitest (5.11.3)
25
+ pry (0.12.2)
26
+ coderay (~> 1.1.0)
27
+ method_source (~> 0.9.0)
28
+ public_suffix (3.0.3)
29
+ rake (12.3.2)
30
+ rspec (3.8.0)
31
+ rspec-core (~> 3.8.0)
32
+ rspec-expectations (~> 3.8.0)
33
+ rspec-mocks (~> 3.8.0)
34
+ rspec-core (3.8.0)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-expectations (3.8.2)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-mocks (3.8.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-support (3.8.0)
43
+ thread_safe (0.3.6)
44
+ tzinfo (1.2.5)
45
+ thread_safe (~> 0.1)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ bundler (~> 1.3)
52
+ oauth-one!
53
+ pry
54
+ rake
55
+ rspec
56
+
57
+ BUNDLED WITH
58
+ 1.17.3
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,45 @@
1
+
2
+ # OAuth-One
3
+
4
+ Simple helper that helps you build the url and make request to a service using OAuth 1.0.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'oauth-one'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install oauth-one
19
+
20
+ ## Usage
21
+
22
+ # Setup data
23
+ method = :get
24
+ domain_url = 'http://some.app.com/auth/'
25
+ user_date = { uid: user_email + encrypted_password }
26
+ oauth_config = { consumer_key: ENV['OAUTH_KEY'], consumer_secret: ENV['OAUTH_SECRET'] }
27
+
28
+ # Usage
29
+ oauth = Oauth::Helper.new(method, domain_url, user_data, oauth_config)
30
+
31
+ # Returns
32
+ oauth.signature_base # Returns the signature appended in the auth url
33
+ oauth.full_url # The proper url used for authentication
34
+
35
+
36
+ After that, all you need to do is to redirect the user to `oauth.full_url`.
37
+
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "oauth_one"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,78 @@
1
+ module OauthOne
2
+
3
+ require 'active_support/core_ext/hash/reverse_merge'
4
+ require 'addressable/uri'
5
+ require 'cgi'
6
+ require 'base64'
7
+ require 'openssl'
8
+ require 'securerandom'
9
+
10
+ MAKE = '0.0.3www'
11
+
12
+ class Helper
13
+ attr_reader :url_params
14
+ attr_reader :method
15
+
16
+ def initialize(method, url, params, options)
17
+ options.reverse_update({
18
+ version: "1.0",
19
+ signature_method: 'HMAC-SHA1',
20
+ timestamp: Time.now.to_i.to_s,
21
+ nonce: SecureRandom.uuid
22
+ })
23
+
24
+ @consumer_secret = options.delete(:consumer_secret)
25
+ @token_secret = options.delete(:token_secret)
26
+ @url_params = params.merge(prepend_oauth_to_key(options))
27
+ @method = method.to_s.upcase
28
+ @url = Addressable::URI.parse(url)
29
+ end
30
+
31
+ def signature_base
32
+ @url_params.delete(:oauth_signature)
33
+ [@method, @url.to_s, url_with_params.query].map{|v| CGI.escape(v) }.join('&')
34
+ end
35
+
36
+ def full_url
37
+ append_signature_to_params
38
+ url_with_params.to_s
39
+ end
40
+
41
+ def make_request
42
+ oauth_signature = CGI.escape(Base64.encode64("#{OpenSSL::HMAC.digest('sha1',self.url_params[:oauth_consumer_key], self.signature_base)}").chomp)
43
+ urlm = URI(self.full_url )
44
+ http = Net::HTTP.new(urlm.host, urlm.port)
45
+ method_type = self.method.to_s.capitalize
46
+ http_obj = "Net::HTTP::#{method_type}".classify.constantize
47
+ request = http_obj.new(urlm)
48
+ request["cache-control"] = 'no-cache'
49
+ http.use_ssl = (urlm.scheme == "https")
50
+ response = http.request(request)
51
+ obj = JSON.parse(response.read_body)
52
+ end
53
+
54
+
55
+ private
56
+ def key
57
+ @token_secret ? "#{CGI.escape(@consumer_secret)}&#{CGI.escape(@token_secret)}" : "#{CGI.escape(@consumer_secret)}&"
58
+ end
59
+
60
+ def url_with_params
61
+ @url.dup.tap{|url| url.query_values = url_params}
62
+ end
63
+
64
+ def append_signature_to_params
65
+ @url_params[:oauth_signature] = hmac_sha1_signature(key, signature_base)
66
+ end
67
+
68
+ def prepend_oauth_to_key(options)
69
+ Hash[options.map{|key, value| ["oauth_#{key}".to_sym, value]}]
70
+ end
71
+
72
+ def hmac_sha1_signature(key, signature_string)
73
+ digest = OpenSSL::Digest.new('sha1')
74
+ hmac = OpenSSL::HMAC.digest(digest, key, signature_string)
75
+ Base64.encode64(hmac).chomp.gsub(/\n/, '')
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module OauthOne
2
+ VERSION = '0.0.2'
3
+ end
data/lib/oauth_one.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "oauth_one/version"
2
+ require "oauth_one/helper"
3
+
4
+ module OauthOne
5
+ end
data/oauth_one.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'oauth_one/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "oauth-one"
8
+ spec.version = OauthOne::VERSION
9
+ spec.authors = ["Innocent Udeogu"]
10
+ spec.email = ["innocentudeh@gmail.com"]
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 = "https://innaticles.github.io"
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
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_dependency "addressable"
27
+ spec.add_dependency "activesupport", "> 3.0.11"
28
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe OauthOne::Helper do
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
+
9
+ let(:helper) { OauthOne::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
+
14
+ it 'prepends "oauth_" to option keys' do
15
+ expect(url_params.keys).to include(:oauth_consumer_key)
16
+ end
17
+
18
+ it 'has some default options' do
19
+ expect(url_params.keys).to include(:oauth_version)
20
+ end
21
+
22
+ it 'does not include the consumer_secret' do
23
+ expect(url_params.keys).to_not include('oauth_consumer_secret')
24
+ end
25
+
26
+ it 'does not have oauth_token as a param' do
27
+ expect(url_params[:oauth_token]).to be_nil
28
+ end
29
+
30
+ it 'returns an array with the options and the params' do
31
+ expect(url_params.keys).to have(6).items
32
+ end
33
+
34
+ it 'has any user specified params' do
35
+ expect(url_params.keys).to include(:user_specified_param)
36
+ end
37
+ end
38
+
39
+ describe '#signature_base' do
40
+ let(:signature_base) { helper.signature_base }
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/)
46
+ end
47
+
48
+ it 'contains the url' do
49
+ expect(signature_base).to match(/example.com/)
50
+ end
51
+
52
+ it 'contains the params' do
53
+ expect(signature_base).to match(/oauth_consumer_key/)
54
+ expect(signature_base).to match(/user_specified_param/)
55
+ end
56
+ end
57
+
58
+ describe '#full_url' do
59
+ let(:full_url) { helper.full_url }
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
+ end
66
+ end
@@ -0,0 +1,8 @@
1
+ require 'oauth_one'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ config.order = 'random'
8
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth-one
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Innocent Udeogu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: addressable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.11
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.11
97
+ description: Simple OAuth 1.0 Helper to generate URLs with HMAC-SHA1 encoding.
98
+ email:
99
+ - innocentudeh@gmail.com
100
+ executables:
101
+ - console
102
+ - setup
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".ruby-gemset"
108
+ - ".ruby-version"
109
+ - ".travis.yml"
110
+ - Gemfile
111
+ - Gemfile.lock
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - bin/console
116
+ - bin/setup
117
+ - lib/oauth_one.rb
118
+ - lib/oauth_one/helper.rb
119
+ - lib/oauth_one/version.rb
120
+ - oauth_one.gemspec
121
+ - spec/oauth_one/helper_spec.rb
122
+ - spec/spec_helper.rb
123
+ homepage: https://innaticles.github.io
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.11
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: In case you need to craft an OAuth 1.0 URL with HMAC-SHA1, this may be helpful.
147
+ test_files:
148
+ - spec/oauth_one/helper_spec.rb
149
+ - spec/spec_helper.rb