oauth2 1.4.4 → 2.0.9

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +242 -64
  3. data/CODE_OF_CONDUCT.md +105 -46
  4. data/CONTRIBUTING.md +27 -1
  5. data/LICENSE +1 -1
  6. data/README.md +445 -140
  7. data/SECURITY.md +26 -0
  8. data/lib/oauth2/access_token.rb +70 -28
  9. data/lib/oauth2/authenticator.rb +12 -5
  10. data/lib/oauth2/client.rb +208 -65
  11. data/lib/oauth2/error.rb +43 -24
  12. data/lib/oauth2/response.rb +81 -22
  13. data/lib/oauth2/strategy/assertion.rb +66 -39
  14. data/lib/oauth2/strategy/auth_code.rb +16 -3
  15. data/lib/oauth2/strategy/base.rb +2 -0
  16. data/lib/oauth2/strategy/client_credentials.rb +4 -2
  17. data/lib/oauth2/strategy/implicit.rb +10 -1
  18. data/lib/oauth2/strategy/password.rb +5 -3
  19. data/lib/oauth2/version.rb +3 -55
  20. data/lib/oauth2.rb +29 -1
  21. metadata +91 -105
  22. data/.document +0 -5
  23. data/.gitignore +0 -19
  24. data/.jrubyrc +0 -1
  25. data/.rspec +0 -2
  26. data/.rubocop.yml +0 -80
  27. data/.rubocop_rspec.yml +0 -26
  28. data/.rubocop_todo.yml +0 -15
  29. data/.ruby-version +0 -1
  30. data/.travis.yml +0 -87
  31. data/Gemfile +0 -40
  32. data/Rakefile +0 -45
  33. data/gemfiles/jruby_1.7.gemfile +0 -11
  34. data/gemfiles/jruby_9.0.gemfile +0 -7
  35. data/gemfiles/jruby_9.1.gemfile +0 -3
  36. data/gemfiles/jruby_9.2.gemfile +0 -3
  37. data/gemfiles/jruby_head.gemfile +0 -3
  38. data/gemfiles/ruby_1.9.gemfile +0 -11
  39. data/gemfiles/ruby_2.0.gemfile +0 -6
  40. data/gemfiles/ruby_2.1.gemfile +0 -6
  41. data/gemfiles/ruby_2.2.gemfile +0 -3
  42. data/gemfiles/ruby_2.3.gemfile +0 -3
  43. data/gemfiles/ruby_2.4.gemfile +0 -3
  44. data/gemfiles/ruby_2.5.gemfile +0 -3
  45. data/gemfiles/ruby_2.6.gemfile +0 -9
  46. data/gemfiles/ruby_2.7.gemfile +0 -9
  47. data/gemfiles/ruby_head.gemfile +0 -9
  48. data/gemfiles/truffleruby.gemfile +0 -3
  49. data/lib/oauth2/mac_token.rb +0 -122
  50. data/oauth2.gemspec +0 -52
data/Rakefile DELETED
@@ -1,45 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # !/usr/bin/env rake
4
-
5
- require 'bundler/gem_tasks'
6
-
7
- begin
8
- require 'wwtd/tasks'
9
- rescue LoadError
10
- puts 'failed to load wwtd'
11
- end
12
-
13
- begin
14
- require 'rspec/core/rake_task'
15
- RSpec::Core::RakeTask.new(:spec)
16
- rescue LoadError
17
- task :spec do
18
- warn 'rspec is disabled'
19
- end
20
- end
21
- task :test => :spec
22
-
23
- begin
24
- require 'rubocop/rake_task'
25
- RuboCop::RakeTask.new do |task|
26
- task.options = ['-D'] # Display the name of the failing cops
27
- end
28
- rescue LoadError
29
- task :rubocop do
30
- warn 'RuboCop is disabled'
31
- end
32
- end
33
-
34
- namespace :doc do
35
- require 'rdoc/task'
36
- require File.expand_path('../lib/oauth2/version', __FILE__)
37
- RDoc::Task.new do |rdoc|
38
- rdoc.rdoc_dir = 'rdoc'
39
- rdoc.title = "oauth2 #{OAuth2::Version}"
40
- rdoc.main = 'README.md'
41
- rdoc.rdoc_files.include('README.md', 'LICENSE.md', 'lib/**/*.rb')
42
- end
43
- end
44
-
45
- task :default => [:test, :rubocop]
@@ -1,11 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'faraday', '~> 0.15.4'
4
-
5
- gem 'json', '< 2.0'
6
- gem 'rack', '~> 1.2'
7
- gem 'rake', [">= 10.0", "< 12"]
8
- gem 'term-ansicolor', '< 1.4.0'
9
- gem 'tins', '< 1.7'
10
-
11
- gemspec :path => '../'
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'faraday', '~> 0.15.4'
4
-
5
- gem 'rake', [">= 10.0", "< 12"]
6
-
7
- gemspec :path => '../'
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '../'
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '../'
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '../'
@@ -1,11 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'faraday', '~> 0.15.4'
4
-
5
- gem 'json', '< 2.0'
6
- gem 'rack', '~> 1.2'
7
- gem 'rake', [">= 10.0", "< 12"]
8
- gem 'term-ansicolor', '< 1.4.0'
9
- gem 'tins', '< 1.7'
10
-
11
- gemspec :path => '../'
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'faraday', '~> 0.15.4'
4
- gem 'rack', '~> 1.2'
5
-
6
- gemspec :path => '../'
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'faraday', '~> 0.15.4'
4
- gem 'rack', '~> 1.2'
5
-
6
- gemspec :path => '../'
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '../'
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '../'
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '../'
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '../'
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- group :development do
4
- gem 'pry'
5
- gem 'byebug'
6
- gem 'pry-byebug'
7
- end
8
-
9
- gemspec :path => '../'
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- group :development do
4
- gem 'pry'
5
- gem 'byebug'
6
- gem 'pry-byebug'
7
- end
8
-
9
- gemspec :path => '../'
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- group :development do
4
- gem 'pry'
5
- gem 'byebug'
6
- gem 'pry-byebug'
7
- end
8
-
9
- gemspec :path => '../'
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '../'
@@ -1,122 +0,0 @@
1
- require 'base64'
2
- require 'digest'
3
- require 'openssl'
4
- require 'securerandom'
5
-
6
- module OAuth2
7
- class MACToken < AccessToken
8
- # Generates a MACToken from an AccessToken and secret
9
- #
10
- # @param [AccessToken] token the OAuth2::Token instance
11
- # @option [String] secret the secret key value
12
- # @param [Hash] opts the options to create the Access Token with
13
- # @see MACToken#initialize
14
- def self.from_access_token(token, secret, options = {})
15
- new(token.client, token.token, secret, token.params.merge(:refresh_token => token.refresh_token, :expires_in => token.expires_in, :expires_at => token.expires_at).merge(options))
16
- end
17
-
18
- attr_reader :secret, :algorithm
19
-
20
- # Initalize a MACToken
21
- #
22
- # @param [Client] client the OAuth2::Client instance
23
- # @param [String] token the Access Token value
24
- # @option [String] secret the secret key value
25
- # @param [Hash] opts the options to create the Access Token with
26
- # @option opts [String] :refresh_token (nil) the refresh_token value
27
- # @option opts [FixNum, String] :expires_in (nil) the number of seconds in which the AccessToken will expire
28
- # @option opts [FixNum, String] :expires_at (nil) the epoch time in seconds in which AccessToken will expire
29
- # @option opts [FixNum, String] :algorithm (hmac-sha-256) the algorithm to use for the HMAC digest (one of 'hmac-sha-256', 'hmac-sha-1')
30
- def initialize(client, token, secret, opts = {})
31
- @secret = secret
32
- self.algorithm = opts.delete(:algorithm) || 'hmac-sha-256'
33
-
34
- super(client, token, opts)
35
- end
36
-
37
- # Make a request with the MAC Token
38
- #
39
- # @param [Symbol] verb the HTTP request method
40
- # @param [String] path the HTTP URL path of the request
41
- # @param [Hash] opts the options to make the request with
42
- # @see Client#request
43
- def request(verb, path, opts = {}, &block)
44
- url = client.connection.build_url(path, opts[:params]).to_s
45
-
46
- opts[:headers] ||= {}
47
- opts[:headers]['Authorization'] = header(verb, url)
48
-
49
- @client.request(verb, path, opts, &block)
50
- end
51
-
52
- # Get the headers hash (always an empty hash)
53
- def headers
54
- {}
55
- end
56
-
57
- # Generate the MAC header
58
- #
59
- # @param [Symbol] verb the HTTP request method
60
- # @param [String] url the HTTP URL path of the request
61
- def header(verb, url)
62
- timestamp = Time.now.utc.to_i
63
- nonce = Digest::MD5.hexdigest([timestamp, SecureRandom.hex].join(':'))
64
-
65
- uri = URI.parse(url)
66
-
67
- raise(ArgumentError, "could not parse \"#{url}\" into URI") unless uri.is_a?(URI::HTTP)
68
-
69
- mac = signature(timestamp, nonce, verb, uri)
70
-
71
- "MAC id=\"#{token}\", ts=\"#{timestamp}\", nonce=\"#{nonce}\", mac=\"#{mac}\""
72
- end
73
-
74
- # Generate the Base64-encoded HMAC digest signature
75
- #
76
- # @param [Fixnum] timestamp the timestamp of the request in seconds since epoch
77
- # @param [String] nonce the MAC header nonce
78
- # @param [Symbol] verb the HTTP request method
79
- # @param [String] url the HTTP URL path of the request
80
- def signature(timestamp, nonce, verb, uri)
81
- signature = [
82
- timestamp,
83
- nonce,
84
- verb.to_s.upcase,
85
- uri.request_uri,
86
- uri.host,
87
- uri.port,
88
- '', nil
89
- ].join("\n")
90
-
91
- strict_encode64(OpenSSL::HMAC.digest(@algorithm, secret, signature))
92
- end
93
-
94
- # Set the HMAC algorithm
95
- #
96
- # @param [String] alg the algorithm to use (one of 'hmac-sha-1', 'hmac-sha-256')
97
- def algorithm=(alg)
98
- @algorithm = begin
99
- case alg.to_s
100
- when 'hmac-sha-1'
101
- OpenSSL::Digest::SHA1.new
102
- when 'hmac-sha-256'
103
- OpenSSL::Digest::SHA256.new
104
- else
105
- raise(ArgumentError, 'Unsupported algorithm')
106
- end
107
- end
108
- end
109
-
110
- private
111
-
112
- # No-op since we need the verb and path
113
- # and the MAC always goes in a header
114
- def token=(_noop)
115
- end
116
-
117
- # Base64.strict_encode64 is not available on Ruby 1.8.7
118
- def strict_encode64(str)
119
- Base64.encode64(str).delete("\n")
120
- end
121
- end
122
- end
data/oauth2.gemspec DELETED
@@ -1,52 +0,0 @@
1
- # coding: utf-8
2
-
3
- lib = File.expand_path('../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'oauth2/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.add_dependency 'faraday', ['>= 0.8', '< 2.0']
9
- spec.add_dependency 'jwt', ['>= 1.0', '< 3.0']
10
- spec.add_dependency 'multi_json', '~> 1.3'
11
- spec.add_dependency 'multi_xml', '~> 0.5'
12
- spec.add_dependency 'rack', ['>= 1.2', '< 3']
13
-
14
- spec.authors = ['Peter Boling', 'Michael Bleigh', 'Erik Michaels-Ober']
15
- spec.description = 'A Ruby wrapper for the OAuth 2.0 protocol built with a similar style to the original OAuth spec.'
16
- spec.email = ['peter.boling@gmail.com']
17
- spec.homepage = 'https://github.com/oauth-xx/oauth2'
18
- spec.licenses = %w[MIT]
19
- spec.name = 'oauth2'
20
- spec.required_ruby_version = '>= 1.9.0'
21
- spec.required_rubygems_version = '>= 1.3.5'
22
- spec.summary = 'A Ruby wrapper for the OAuth 2.0 protocol.'
23
- spec.version = OAuth2::Version
24
-
25
- spec.metadata = {
26
- 'bug_tracker_uri' => 'https://github.com/oauth-xx/oauth2/issues',
27
- 'changelog_uri' => "https://github.com/oauth-xx/oauth2/blob/v#{spec.version}/CHANGELOG.md",
28
- 'documentation_uri' => "https://www.rubydoc.info/gems/oauth2/#{spec.version}",
29
- 'source_code_uri' => "https://github.com/oauth-xx/oauth2/tree/v#{spec.version}",
30
- 'wiki_uri' => 'https://github.com/oauth-xx/oauth2/wiki'
31
- }
32
-
33
- spec.require_paths = %w[lib]
34
- spec.bindir = 'exe'
35
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
37
- f.match(%r{^(bin|test|spec|features)/})
38
- end
39
-
40
- spec.add_development_dependency 'addressable', '~> 2.3'
41
- spec.add_development_dependency 'backports', '~> 3.11'
42
- spec.add_development_dependency 'bundler', '>= 1.16'
43
- spec.add_development_dependency 'coveralls', '~> 0.8'
44
- spec.add_development_dependency 'rake', '~> 12.3'
45
- spec.add_development_dependency 'rdoc', ['>= 5.0', '< 7']
46
- spec.add_development_dependency 'rspec', '~> 3.0'
47
- spec.add_development_dependency 'rspec-stubbed_env'
48
- spec.add_development_dependency 'rspec-pending_for'
49
- spec.add_development_dependency 'rspec-block_is_expected'
50
- spec.add_development_dependency 'silent_stream'
51
- spec.add_development_dependency 'wwtd'
52
- end