oauth2 1.0.0 → 1.1.0
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 +4 -4
- data/README.md +0 -1
- data/lib/oauth2/access_token.rb +7 -7
- data/lib/oauth2/client.rb +3 -3
- data/lib/oauth2/mac_token.rb +6 -8
- data/lib/oauth2/response.rb +22 -22
- data/lib/oauth2/strategy/assertion.rb +2 -2
- data/lib/oauth2/strategy/client_credentials.rb +2 -2
- data/lib/oauth2/version.rb +55 -11
- data/oauth2.gemspec +3 -6
- metadata +18 -29
- data/Rakefile +0 -39
- data/spec/helper.rb +0 -42
- data/spec/oauth2/access_token_spec.rb +0 -169
- data/spec/oauth2/client_spec.rb +0 -215
- data/spec/oauth2/mac_token_spec.rb +0 -119
- data/spec/oauth2/response_spec.rb +0 -91
- data/spec/oauth2/strategy/assertion_spec.rb +0 -56
- data/spec/oauth2/strategy/auth_code_spec.rb +0 -88
- data/spec/oauth2/strategy/base_spec.rb +0 -7
- data/spec/oauth2/strategy/client_credentials_spec.rb +0 -81
- data/spec/oauth2/strategy/implicit_spec.rb +0 -28
- data/spec/oauth2/strategy/password_spec.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e6df01671ac06be9840d38d64d3cc349e3f8a41
|
4
|
+
data.tar.gz: 4ebfa842881a53f3c98cc407646614f5f8883cbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fde60355bd37fd6ab71e9f103fae0d4fbb065b62c4070c95aef84842fb9cfce6a6125e75a0e78e98c87c54c32ccc72042a1c5cfae514d534799310ac5a82e0c6
|
7
|
+
data.tar.gz: 6c358951c337a85275fe064a599e2fa03d92c4eeb3425d3ec2e51b857aa42cdcfd31ab1e1a2e77a2e9780c246970a0bcde4c3ae2e42c5775847e951faf45be28
|
data/README.md
CHANGED
data/lib/oauth2/access_token.rb
CHANGED
@@ -36,7 +36,7 @@ module OAuth2
|
|
36
36
|
# @option opts [String] :header_format ('Bearer %s') the string format to use for the Authorization header
|
37
37
|
# @option opts [String] :param_name ('access_token') the parameter name to use for transmission of the
|
38
38
|
# Access Token value in :body or :query transmission mode
|
39
|
-
def initialize(client, token, opts = {})
|
39
|
+
def initialize(client, token, opts = {}) # rubocop:disable Metrics/AbcSize
|
40
40
|
@client = client
|
41
41
|
@token = token.to_s
|
42
42
|
[:refresh_token, :expires_in, :expires_at].each do |arg|
|
@@ -63,7 +63,7 @@ module OAuth2
|
|
63
63
|
#
|
64
64
|
# @return [Boolean]
|
65
65
|
def expires?
|
66
|
-
!!@expires_at
|
66
|
+
!!@expires_at
|
67
67
|
end
|
68
68
|
|
69
69
|
# Whether or not the token is expired
|
@@ -79,10 +79,10 @@ module OAuth2
|
|
79
79
|
# @note options should be carried over to the new AccessToken
|
80
80
|
def refresh!(params = {})
|
81
81
|
fail('A refresh_token is not available') unless refresh_token
|
82
|
-
params
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
params[:client_id] = @client.id
|
83
|
+
params[:client_secret] = @client.secret
|
84
|
+
params[:grant_type] = 'refresh_token'
|
85
|
+
params[:refresh_token] = refresh_token
|
86
86
|
new_token = @client.get_token(params)
|
87
87
|
new_token.options = options
|
88
88
|
new_token.refresh_token = refresh_token unless new_token.refresh_token
|
@@ -149,7 +149,7 @@ module OAuth2
|
|
149
149
|
|
150
150
|
private
|
151
151
|
|
152
|
-
def token=(opts) # rubocop:disable MethodLength
|
152
|
+
def token=(opts) # rubocop:disable MethodLength, Metrics/AbcSize
|
153
153
|
case options[:mode]
|
154
154
|
when :header
|
155
155
|
opts[:headers] ||= {}
|
data/lib/oauth2/client.rb
CHANGED
@@ -85,7 +85,7 @@ module OAuth2
|
|
85
85
|
# code response for this request. Will default to client option
|
86
86
|
# @option opts [Symbol] :parse @see Response::initialize
|
87
87
|
# @yield [req] The Faraday request
|
88
|
-
def request(verb, url, opts = {}) # rubocop:disable CyclomaticComplexity, MethodLength
|
88
|
+
def request(verb, url, opts = {}) # rubocop:disable CyclomaticComplexity, MethodLength, Metrics/AbcSize
|
89
89
|
connection.response :logger, ::Logger.new($stdout) if ENV['OAUTH_DEBUG'] == 'true'
|
90
90
|
|
91
91
|
url = connection.build_url(url, opts[:params]).to_s
|
@@ -125,12 +125,12 @@ module OAuth2
|
|
125
125
|
# @param [Hash] access token options, to pass to the AccessToken object
|
126
126
|
# @param [Class] class of access token for easier subclassing OAuth2::AccessToken
|
127
127
|
# @return [AccessToken] the initalized AccessToken
|
128
|
-
def get_token(params, access_token_opts = {}, access_token_class = AccessToken)
|
128
|
+
def get_token(params, access_token_opts = {}, access_token_class = AccessToken) # rubocop:disable Metrics/AbcSize
|
129
129
|
opts = {:raise_errors => options[:raise_errors], :parse => params.delete(:parse)}
|
130
130
|
if options[:token_method] == :post
|
131
131
|
headers = params.delete(:headers)
|
132
132
|
opts[:body] = params
|
133
|
-
opts[:headers] =
|
133
|
+
opts[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
|
134
134
|
opts[:headers].merge!(headers) if headers
|
135
135
|
else
|
136
136
|
opts[:params] = params
|
data/lib/oauth2/mac_token.rb
CHANGED
@@ -12,11 +12,7 @@ module OAuth2
|
|
12
12
|
# @param [Hash] opts the options to create the Access Token with
|
13
13
|
# @see MACToken#initialize
|
14
14
|
def self.from_access_token(token, secret, options = {})
|
15
|
-
new(token.client, token.token, secret, token.params.merge(
|
16
|
-
:refresh_token => token.refresh_token,
|
17
|
-
:expires_in => token.expires_in,
|
18
|
-
:expires_at => token.expires_at
|
19
|
-
).merge(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))
|
20
16
|
end
|
21
17
|
|
22
18
|
attr_reader :secret, :algorithm
|
@@ -48,7 +44,7 @@ module OAuth2
|
|
48
44
|
url = client.connection.build_url(path, opts[:params]).to_s
|
49
45
|
|
50
46
|
opts[:headers] ||= {}
|
51
|
-
opts[:headers]
|
47
|
+
opts[:headers]['Authorization'] = header(verb, url)
|
52
48
|
|
53
49
|
@client.request(verb, path, opts, &block)
|
54
50
|
end
|
@@ -99,7 +95,8 @@ module OAuth2
|
|
99
95
|
#
|
100
96
|
# @param [String] alg the algorithm to use (one of 'hmac-sha-1', 'hmac-sha-256')
|
101
97
|
def algorithm=(alg)
|
102
|
-
@algorithm =
|
98
|
+
@algorithm = begin
|
99
|
+
case alg.to_s
|
103
100
|
when 'hmac-sha-1'
|
104
101
|
OpenSSL::Digest::SHA1.new
|
105
102
|
when 'hmac-sha-256'
|
@@ -107,6 +104,7 @@ module OAuth2
|
|
107
104
|
else
|
108
105
|
fail(ArgumentError, 'Unsupported algorithm')
|
109
106
|
end
|
107
|
+
end
|
110
108
|
end
|
111
109
|
|
112
110
|
private
|
@@ -118,7 +116,7 @@ module OAuth2
|
|
118
116
|
|
119
117
|
# Base64.strict_encode64 is not available on Ruby 1.8.7
|
120
118
|
def strict_encode64(str)
|
121
|
-
Base64.encode64(str).
|
119
|
+
Base64.encode64(str).delete("\n")
|
122
120
|
end
|
123
121
|
end
|
124
122
|
end
|
data/lib/oauth2/response.rb
CHANGED
@@ -8,6 +8,22 @@ module OAuth2
|
|
8
8
|
attr_reader :response
|
9
9
|
attr_accessor :error, :options
|
10
10
|
|
11
|
+
# Procs that, when called, will parse a response body according
|
12
|
+
# to the specified format.
|
13
|
+
@@parsers = {
|
14
|
+
:json => lambda { |body| MultiJson.load(body) rescue body }, # rubocop:disable RescueModifier
|
15
|
+
:query => lambda { |body| Rack::Utils.parse_query(body) },
|
16
|
+
:text => lambda { |body| body },
|
17
|
+
}
|
18
|
+
|
19
|
+
# Content type assignments for various potential HTTP content types.
|
20
|
+
@@content_types = {
|
21
|
+
'application/json' => :json,
|
22
|
+
'text/javascript' => :json,
|
23
|
+
'application/x-www-form-urlencoded' => :query,
|
24
|
+
'text/plain' => :text,
|
25
|
+
}
|
26
|
+
|
11
27
|
# Adds a new content type parser.
|
12
28
|
#
|
13
29
|
# @param [Symbol] key A descriptive symbol key such as :json or :query.
|
@@ -15,9 +31,9 @@ module OAuth2
|
|
15
31
|
# @yield [String] A block returning parsed content.
|
16
32
|
def self.register_parser(key, mime_types, &block)
|
17
33
|
key = key.to_sym
|
18
|
-
|
34
|
+
@@parsers[key] = block
|
19
35
|
Array(mime_types).each do |mime_type|
|
20
|
-
|
36
|
+
@@content_types[mime_type] = key
|
21
37
|
end
|
22
38
|
end
|
23
39
|
|
@@ -47,28 +63,12 @@ module OAuth2
|
|
47
63
|
response.body || ''
|
48
64
|
end
|
49
65
|
|
50
|
-
# Procs that, when called, will parse a response body according
|
51
|
-
# to the specified format.
|
52
|
-
PARSERS = {
|
53
|
-
:json => lambda { |body| MultiJson.load(body) rescue body }, # rubocop:disable RescueModifier
|
54
|
-
:query => lambda { |body| Rack::Utils.parse_query(body) },
|
55
|
-
:text => lambda { |body| body }
|
56
|
-
}
|
57
|
-
|
58
|
-
# Content type assignments for various potential HTTP content types.
|
59
|
-
CONTENT_TYPES = {
|
60
|
-
'application/json' => :json,
|
61
|
-
'text/javascript' => :json,
|
62
|
-
'application/x-www-form-urlencoded' => :query,
|
63
|
-
'text/plain' => :text
|
64
|
-
}
|
65
|
-
|
66
66
|
# The parsed response body.
|
67
67
|
# Will attempt to parse application/x-www-form-urlencoded and
|
68
68
|
# application/json Content-Type response bodies
|
69
69
|
def parsed
|
70
|
-
return nil unless
|
71
|
-
@parsed ||=
|
70
|
+
return nil unless @@parsers.key?(parser)
|
71
|
+
@parsed ||= @@parsers[parser].call(body)
|
72
72
|
end
|
73
73
|
|
74
74
|
# Attempts to determine the content type of the response.
|
@@ -78,8 +78,8 @@ module OAuth2
|
|
78
78
|
|
79
79
|
# Determines the parser that will be used to supply the content of #parsed
|
80
80
|
def parser
|
81
|
-
return options[:parse].to_sym if
|
82
|
-
|
81
|
+
return options[:parse].to_sym if @@parsers.key?(options[:parse])
|
82
|
+
@@content_types[content_type]
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -52,7 +52,7 @@ module OAuth2
|
|
52
52
|
{:grant_type => 'assertion',
|
53
53
|
:assertion_type => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
54
54
|
:assertion => assertion,
|
55
|
-
:scope => params[:scope]
|
55
|
+
:scope => params[:scope],
|
56
56
|
}.merge(client_params)
|
57
57
|
end
|
58
58
|
|
@@ -60,7 +60,7 @@ module OAuth2
|
|
60
60
|
claims = {:iss => params[:iss],
|
61
61
|
:aud => params[:aud],
|
62
62
|
:prn => params[:prn],
|
63
|
-
:exp => params[:exp]
|
63
|
+
:exp => params[:exp],
|
64
64
|
}
|
65
65
|
if params[:hmac_secret]
|
66
66
|
JWT.encode(claims, params[:hmac_secret], 'HS256')
|
@@ -19,7 +19,7 @@ module OAuth2
|
|
19
19
|
# @param [Hash] opts options
|
20
20
|
def get_token(params = {}, opts = {})
|
21
21
|
request_body = opts.delete('auth_scheme') == 'request_body'
|
22
|
-
params
|
22
|
+
params['grant_type'] = 'client_credentials'
|
23
23
|
params.merge!(request_body ? client_params : {:headers => {'Authorization' => authorization(client_params['client_id'], client_params['client_secret'])}})
|
24
24
|
@client.get_token(params, opts.merge('refresh_token' => nil))
|
25
25
|
end
|
@@ -29,7 +29,7 @@ module OAuth2
|
|
29
29
|
# @param [String] The client ID
|
30
30
|
# @param [String] the client secret
|
31
31
|
def authorization(client_id, client_secret)
|
32
|
-
'Basic ' + Base64.encode64(client_id + ':' + client_secret).
|
32
|
+
'Basic ' + Base64.encode64(client_id + ':' + client_secret).delete("\n")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/oauth2/version.rb
CHANGED
@@ -1,15 +1,59 @@
|
|
1
1
|
module OAuth2
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
2
|
+
module Version
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# The major version
|
6
|
+
#
|
7
|
+
# @return [Integer]
|
8
|
+
def major
|
9
|
+
1
|
10
|
+
end
|
11
|
+
|
12
|
+
# The minor version
|
13
|
+
#
|
14
|
+
# @return [Integer]
|
15
|
+
def minor
|
16
|
+
1
|
17
|
+
end
|
18
|
+
|
19
|
+
# The patch version
|
20
|
+
#
|
21
|
+
# @return [Integer]
|
22
|
+
def patch
|
23
|
+
0
|
24
|
+
end
|
25
|
+
|
26
|
+
# The pre-release version, if any
|
27
|
+
#
|
28
|
+
# @return [Integer, NilClass]
|
29
|
+
def pre
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# The version number as a hash
|
34
|
+
#
|
35
|
+
# @return [Hash]
|
36
|
+
def to_h
|
37
|
+
{
|
38
|
+
:major => major,
|
39
|
+
:minor => minor,
|
40
|
+
:patch => patch,
|
41
|
+
:pre => pre,
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
# The version number as an array
|
46
|
+
#
|
47
|
+
# @return [Array]
|
48
|
+
def to_a
|
49
|
+
[major, minor, patch, pre].compact
|
50
|
+
end
|
51
|
+
|
52
|
+
# The version number as a string
|
53
|
+
#
|
54
|
+
# @return [String]
|
55
|
+
def to_s
|
56
|
+
to_a.join('.')
|
13
57
|
end
|
14
58
|
end
|
15
59
|
end
|
data/oauth2.gemspec
CHANGED
@@ -5,23 +5,20 @@ require 'oauth2/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.add_dependency 'faraday', ['>= 0.8', '< 0.10']
|
8
|
-
spec.add_dependency 'jwt', '~> 1.0'
|
8
|
+
spec.add_dependency 'jwt', '~> 1.0', '< 1.5.2'
|
9
9
|
spec.add_dependency 'multi_json', '~> 1.3'
|
10
10
|
spec.add_dependency 'multi_xml', '~> 0.5'
|
11
|
-
spec.add_dependency 'rack', '
|
11
|
+
spec.add_dependency 'rack', ['>= 1.2', '< 3']
|
12
12
|
spec.add_development_dependency 'bundler', '~> 1.0'
|
13
13
|
spec.authors = ['Michael Bleigh', 'Erik Michaels-Ober']
|
14
14
|
spec.description = 'A Ruby wrapper for the OAuth 2.0 protocol built with a similar style to the original OAuth spec.'
|
15
15
|
spec.email = ['michael@intridea.com', 'sferik@gmail.com']
|
16
|
-
spec.files = %w(.document CONTRIBUTING.md LICENSE.md README.md
|
17
|
-
spec.files += Dir.glob('lib/**/*.rb')
|
18
|
-
spec.files += Dir.glob('spec/**/*')
|
16
|
+
spec.files = %w(.document CONTRIBUTING.md LICENSE.md README.md oauth2.gemspec) + Dir['lib/**/*.rb']
|
19
17
|
spec.homepage = 'http://github.com/intridea/oauth2'
|
20
18
|
spec.licenses = %w(MIT)
|
21
19
|
spec.name = 'oauth2'
|
22
20
|
spec.require_paths = %w(lib)
|
23
21
|
spec.required_rubygems_version = '>= 1.3.5'
|
24
22
|
spec.summary = 'A Ruby wrapper for the OAuth 2.0 protocol.'
|
25
|
-
spec.test_files = Dir.glob('spec/**/*')
|
26
23
|
spec.version = OAuth2::Version
|
27
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -38,6 +38,9 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
|
+
- - "<"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.5.2
|
41
44
|
type: :runtime
|
42
45
|
prerelease: false
|
43
46
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -45,6 +48,9 @@ dependencies:
|
|
45
48
|
- - "~>"
|
46
49
|
- !ruby/object:Gem::Version
|
47
50
|
version: '1.0'
|
51
|
+
- - "<"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.5.2
|
48
54
|
- !ruby/object:Gem::Dependency
|
49
55
|
name: multi_json
|
50
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,16 +83,22 @@ dependencies:
|
|
77
83
|
name: rack
|
78
84
|
requirement: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
|
-
- - "
|
86
|
+
- - ">="
|
81
87
|
- !ruby/object:Gem::Version
|
82
88
|
version: '1.2'
|
89
|
+
- - "<"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '3'
|
83
92
|
type: :runtime
|
84
93
|
prerelease: false
|
85
94
|
version_requirements: !ruby/object:Gem::Requirement
|
86
95
|
requirements:
|
87
|
-
- - "
|
96
|
+
- - ">="
|
88
97
|
- !ruby/object:Gem::Version
|
89
98
|
version: '1.2'
|
99
|
+
- - "<"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '3'
|
90
102
|
- !ruby/object:Gem::Dependency
|
91
103
|
name: bundler
|
92
104
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,7 +126,6 @@ files:
|
|
114
126
|
- CONTRIBUTING.md
|
115
127
|
- LICENSE.md
|
116
128
|
- README.md
|
117
|
-
- Rakefile
|
118
129
|
- lib/oauth2.rb
|
119
130
|
- lib/oauth2/access_token.rb
|
120
131
|
- lib/oauth2/client.rb
|
@@ -129,17 +140,6 @@ files:
|
|
129
140
|
- lib/oauth2/strategy/password.rb
|
130
141
|
- lib/oauth2/version.rb
|
131
142
|
- oauth2.gemspec
|
132
|
-
- spec/helper.rb
|
133
|
-
- spec/oauth2/access_token_spec.rb
|
134
|
-
- spec/oauth2/client_spec.rb
|
135
|
-
- spec/oauth2/mac_token_spec.rb
|
136
|
-
- spec/oauth2/response_spec.rb
|
137
|
-
- spec/oauth2/strategy/assertion_spec.rb
|
138
|
-
- spec/oauth2/strategy/auth_code_spec.rb
|
139
|
-
- spec/oauth2/strategy/base_spec.rb
|
140
|
-
- spec/oauth2/strategy/client_credentials_spec.rb
|
141
|
-
- spec/oauth2/strategy/implicit_spec.rb
|
142
|
-
- spec/oauth2/strategy/password_spec.rb
|
143
143
|
homepage: http://github.com/intridea/oauth2
|
144
144
|
licenses:
|
145
145
|
- MIT
|
@@ -160,20 +160,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
160
|
version: 1.3.5
|
161
161
|
requirements: []
|
162
162
|
rubyforge_project:
|
163
|
-
rubygems_version: 2.2.
|
163
|
+
rubygems_version: 2.2.5
|
164
164
|
signing_key:
|
165
165
|
specification_version: 4
|
166
166
|
summary: A Ruby wrapper for the OAuth 2.0 protocol.
|
167
|
-
test_files:
|
168
|
-
- spec/helper.rb
|
169
|
-
- spec/oauth2/access_token_spec.rb
|
170
|
-
- spec/oauth2/client_spec.rb
|
171
|
-
- spec/oauth2/mac_token_spec.rb
|
172
|
-
- spec/oauth2/response_spec.rb
|
173
|
-
- spec/oauth2/strategy/assertion_spec.rb
|
174
|
-
- spec/oauth2/strategy/auth_code_spec.rb
|
175
|
-
- spec/oauth2/strategy/base_spec.rb
|
176
|
-
- spec/oauth2/strategy/client_credentials_spec.rb
|
177
|
-
- spec/oauth2/strategy/implicit_spec.rb
|
178
|
-
- spec/oauth2/strategy/password_spec.rb
|
167
|
+
test_files: []
|
179
168
|
has_rdoc:
|