omniauth-oauth2 1.3.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 97b27d270aece449c0fbd5318ef61056b3179b03
4
- data.tar.gz: 94cc90831da565635c64c5ff036926c7999d3619
2
+ SHA256:
3
+ metadata.gz: 35d242e59c9afdaf9936548a38aa617b67ff9d24be62bb019e3f2c448d0304a3
4
+ data.tar.gz: 0340fe1535cf2eddaa261a5306394b7a5381136df2f735c77fc4441eaeb8e107
5
5
  SHA512:
6
- metadata.gz: 021f0ccaed1fb0bca365ea86ffc31c955e678da42fdad37f8083c71132d7f365af84d0f21da143f6328cb658a26d4e789249d9743899c776bf3872fda0529b9b
7
- data.tar.gz: 68ad4394e13f8adce5aac65da939f823b572ab58d11928ee05d1fba4e932360db79893e1038ac7d039094467c9a3fe98fea564a064b4802ff06d0a53082a549e
6
+ metadata.gz: e87d41e2854c624939d2142654ab9adf11a7336a199d2cfc3790f3eaccc07a62a43715fbb07c9353bccc5160c2dd06369415da70f69e9ed8d980ef6d76b415bc
7
+ data.tar.gz: bae2d1d3f173a93cceb14809efdc72bba6c40373102e65da1df03881ba4799a4d18446e2de072da56572e94c73d807cffe00e55daaf7de370325563409798a5b
@@ -1,10 +1,35 @@
1
- Metrics/BlockNesting:
2
- Max: 2
1
+ AllCops:
2
+ NewCops: enable
3
+
4
+ Gemspec/RequiredRubyVersion:
5
+ Enabled: false
3
6
 
4
- Metrics/LineLength:
7
+ Layout/AccessModifierIndentation:
8
+ EnforcedStyle: outdent
9
+
10
+ Layout/LineLength:
5
11
  AllowURI: true
6
12
  Enabled: false
7
13
 
14
+ Layout/SpaceInsideHashLiteralBraces:
15
+ EnforcedStyle: no_space
16
+
17
+ Lint/MissingSuper:
18
+ Enabled: false
19
+
20
+ Metrics/AbcSize:
21
+ Max: 18
22
+
23
+ Metrics/BlockLength:
24
+ Exclude:
25
+ - spec/omniauth/strategies/oauth2_spec.rb
26
+
27
+ Metrics/BlockNesting:
28
+ Max: 2
29
+
30
+ Metrics/ClassLength:
31
+ Max: 110
32
+
8
33
  Metrics/MethodLength:
9
34
  CountComments: false
10
35
  Max: 10
@@ -13,8 +38,9 @@ Metrics/ParameterLists:
13
38
  Max: 4
14
39
  CountKeywordArgs: true
15
40
 
16
- Style/AccessModifierIndentation:
17
- EnforcedStyle: outdent
41
+ Naming/FileName:
42
+ Exclude:
43
+ - lib/omniauth-oauth2.rb
18
44
 
19
45
  Style/CollectionMethods:
20
46
  PreferredMethods:
@@ -29,14 +55,26 @@ Style/Documentation:
29
55
  Style/DoubleNegation:
30
56
  Enabled: false
31
57
 
58
+ Style/ExpandPathArguments:
59
+ Enabled: false
60
+
61
+ Style/FrozenStringLiteralComment:
62
+ Enabled: false
63
+
32
64
  Style/HashSyntax:
33
65
  EnforcedStyle: hash_rockets
34
66
 
35
- Style/SpaceInsideHashLiteralBraces:
36
- EnforcedStyle: no_space
67
+ Style/StderrPuts:
68
+ Enabled: false
37
69
 
38
70
  Style/StringLiterals:
39
71
  EnforcedStyle: double_quotes
40
72
 
41
- Style/TrailingComma:
42
- EnforcedStyleForMultiline: 'comma'
73
+ Style/TrailingCommaInArguments:
74
+ EnforcedStyleForMultiline: comma
75
+
76
+ Style/TrailingCommaInHashLiteral:
77
+ EnforcedStyleForMultiline: comma
78
+
79
+ Style/TrailingCommaInArrayLiteral:
80
+ EnforcedStyleForMultiline: comma
@@ -1,18 +1,17 @@
1
- before_install: gem install bundler
1
+ bundler_args: --without development
2
+ before_install:
3
+ - gem update --system
4
+ - gem update bundler
5
+ cache: bundler
2
6
  env:
3
7
  global:
4
8
  - JRUBY_OPTS="$JRUBY_OPTS --debug"
5
9
  language: ruby
6
10
  rvm:
7
- - 1.8.7
8
- - 1.9.3
9
- - 2.0.0
10
- - 2.1
11
- - 2.2
12
- - jruby-18mode
13
- - jruby-19mode
11
+ - jruby-9000
12
+ - 2.4.4
13
+ - 2.5.3
14
14
  - jruby-head
15
- - rbx-2
16
15
  - ruby-head
17
16
  matrix:
18
17
  allow_failures:
data/Gemfile CHANGED
@@ -1,17 +1,18 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
- gem "rake"
3
+ gem "rake", "~> 12.0"
4
4
 
5
5
  group :test do
6
+ gem "addressable", "~> 2.3.8", :platforms => %i[jruby ruby_18]
6
7
  gem "coveralls"
7
- gem "json", :platforms => [:jruby, :ruby_18, :ruby_19]
8
- gem "mime-types", "~> 1.25", :platforms => [:jruby, :ruby_18]
8
+ gem "json", :platforms => %i[jruby ruby_18 ruby_19]
9
+ gem "mime-types", "~> 1.25", :platforms => %i[jruby ruby_18]
9
10
  gem "rack-test"
10
- gem "rest-client", "~> 1.6.0", :platforms => [:jruby, :ruby_18]
11
+ gem "rest-client", "~> 1.8.0", :platforms => %i[jruby ruby_18]
11
12
  gem "rspec", "~> 3.2"
12
- gem "rubocop", ">= 0.30", :platforms => [:ruby_19, :ruby_20, :ruby_21, :ruby_22]
13
+ gem "rubocop", ">= 0.51", :platforms => %i[ruby_19 ruby_20 ruby_21 ruby_22 ruby_23 ruby_24]
13
14
  gem "simplecov", ">= 0.9"
14
- gem "webmock"
15
+ gem "webmock", "~> 3.0"
15
16
  end
16
17
 
17
18
  # Specify your gem's dependencies in omniauth-oauth2.gemspec
data/README.md CHANGED
@@ -1,14 +1,13 @@
1
1
  # OmniAuth OAuth2
2
2
 
3
3
  [![Gem Version](http://img.shields.io/gem/v/omniauth-oauth2.svg)][gem]
4
- [![Build Status](http://img.shields.io/travis/intridea/omniauth-oauth2.svg)][travis]
5
- [![Dependency Status](http://img.shields.io/gemnasium/intridea/omniauth-oauth2.svg)][gemnasium]
6
- [![Code Climate](http://img.shields.io/codeclimate/github/intridea/omniauth-oauth2.svg)][codeclimate]
4
+ [![Build Status](http://img.shields.io/travis/omniauth/omniauth-oauth2.svg)][travis]
5
+ [![Code Climate](http://img.shields.io/codeclimate/maintainability/intridea/omniauth-oauth2.svg)][codeclimate]
7
6
  [![Coverage Status](http://img.shields.io/coveralls/intridea/omniauth-oauth2.svg)][coveralls]
7
+ [![Security](https://hakiri.io/github/omniauth/omniauth-oauth2/master.svg)](https://hakiri.io/github/omniauth/omniauth-oauth2/master)
8
8
 
9
9
  [gem]: https://rubygems.org/gems/omniauth-oauth2
10
- [travis]: http://travis-ci.org/intridea/omniauth-oauth2
11
- [gemnasium]: https://gemnasium.com/intridea/omniauth-oauth2
10
+ [travis]: http://travis-ci.org/omniauth/omniauth-oauth2
12
11
  [codeclimate]: https://codeclimate.com/github/intridea/omniauth-oauth2
13
12
  [coveralls]: https://coveralls.io/r/intridea/omniauth-oauth2
14
13
 
@@ -33,6 +32,10 @@ module OmniAuth
33
32
  # This is where you pass the options you would pass when
34
33
  # initializing your consumer from the OAuth gem.
35
34
  option :client_options, {:site => "https://api.somesite.com"}
35
+
36
+ # You may specify that your strategy should use PKCE by setting
37
+ # the pkce option to true: https://tools.ietf.org/html/rfc7636
38
+ option :pkce, true
36
39
 
37
40
  # These are called after authentication has succeeded. If
38
41
  # possible, you should try to set the UID without making
@@ -63,5 +66,3 @@ end
63
66
  ```
64
67
 
65
68
  That's pretty much it!
66
-
67
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/intridea/omniauth-oauth2/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env rake
2
+
2
3
  require "bundler/gem_tasks"
3
4
  require "rspec/core/rake_task"
4
5
 
@@ -15,4 +16,4 @@ rescue LoadError
15
16
  end
16
17
  end
17
18
 
18
- task :default => [:spec, :rubocop]
19
+ task :default => %i[spec rubocop]
@@ -1,2 +1,2 @@
1
- require "omniauth-oauth2/version" # rubocop:disable FileName
1
+ require "omniauth-oauth2/version"
2
2
  require "omniauth/strategies/oauth2"
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module OAuth2
3
- VERSION = "1.3.0"
3
+ VERSION = "1.7.0".freeze
4
4
  end
5
5
  end
@@ -14,17 +14,32 @@ module OmniAuth
14
14
  class OAuth2
15
15
  include OmniAuth::Strategy
16
16
 
17
- args [:client_id, :client_secret]
17
+ def self.inherited(subclass)
18
+ OmniAuth::Strategy.included(subclass)
19
+ end
20
+
21
+ args %i[client_id client_secret]
18
22
 
19
23
  option :client_id, nil
20
24
  option :client_secret, nil
21
25
  option :client_options, {}
22
26
  option :authorize_params, {}
23
- option :authorize_options, [:scope]
27
+ option :authorize_options, %i[scope state]
24
28
  option :token_params, {}
25
29
  option :token_options, []
26
30
  option :auth_token_params, {}
27
31
  option :provider_ignores_state, false
32
+ option :pkce, false
33
+ option :pkce_verifier, nil
34
+ option :pkce_options, {
35
+ :code_challenge => proc { |verifier|
36
+ Base64.urlsafe_encode64(
37
+ Digest::SHA2.digest(verifier),
38
+ :padding => false,
39
+ )
40
+ },
41
+ :code_challenge_method => "S256",
42
+ }
28
43
 
29
44
  attr_accessor :access_token
30
45
 
@@ -32,15 +47,11 @@ module OmniAuth
32
47
  ::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
33
48
  end
34
49
 
35
- def callback_url
36
- full_host + script_name + callback_path
37
- end
38
-
39
50
  credentials do
40
51
  hash = {"token" => access_token.token}
41
- hash.merge!("refresh_token" => access_token.refresh_token) if access_token.expires? && access_token.refresh_token
42
- hash.merge!("expires_at" => access_token.expires_at) if access_token.expires?
43
- hash.merge!("expires" => access_token.expires?)
52
+ hash["refresh_token"] = access_token.refresh_token if access_token.expires? && access_token.refresh_token
53
+ hash["expires_at"] = access_token.expires_at if access_token.expires?
54
+ hash["expires"] = access_token.expires?
44
55
  hash
45
56
  end
46
57
 
@@ -48,22 +59,29 @@ module OmniAuth
48
59
  redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
49
60
  end
50
61
 
51
- def authorize_params
62
+ def authorize_params # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
52
63
  options.authorize_params[:state] = SecureRandom.hex(24)
53
- params = options.authorize_params.merge(options_for("authorize"))
64
+
54
65
  if OmniAuth.config.test_mode
55
66
  @env ||= {}
56
67
  @env["rack.session"] ||= {}
57
68
  end
69
+
70
+ params = options.authorize_params
71
+ .merge(options_for("authorize"))
72
+ .merge(pkce_authorize_params)
73
+
74
+ session["omniauth.pkce.verifier"] = options.pkce_verifier if options.pkce
58
75
  session["omniauth.state"] = params[:state]
76
+
59
77
  params
60
78
  end
61
79
 
62
80
  def token_params
63
- options.token_params.merge(options_for("token"))
81
+ options.token_params.merge(options_for("token")).merge(pkce_token_params)
64
82
  end
65
83
 
66
- def callback_phase # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, PerceivedComplexity
84
+ def callback_phase # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
67
85
  error = request.params["error_reason"] || request.params["error"]
68
86
  if error
69
87
  fail!(error, CallbackError.new(request.params["error"], request.params["error_description"] || request.params["error_reason"], request.params["error_uri"]))
@@ -84,23 +102,44 @@ module OmniAuth
84
102
 
85
103
  protected
86
104
 
105
+ def pkce_authorize_params
106
+ return {} unless options.pkce
107
+
108
+ options.pkce_verifier = SecureRandom.hex(64)
109
+
110
+ # NOTE: see https://tools.ietf.org/html/rfc7636#appendix-A
111
+ {
112
+ :code_challenge => options.pkce_options[:code_challenge]
113
+ .call(options.pkce_verifier),
114
+ :code_challenge_method => options.pkce_options[:code_challenge_method],
115
+ }
116
+ end
117
+
118
+ def pkce_token_params
119
+ return {} unless options.pkce
120
+
121
+ {:code_verifier => session.delete("omniauth.pkce.verifier")}
122
+ end
123
+
87
124
  def build_access_token
88
125
  verifier = request.params["code"]
89
126
  client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params))
90
127
  end
91
128
 
92
129
  def deep_symbolize(options)
93
- hash = {}
94
- options.each do |key, value|
130
+ options.each_with_object({}) do |(key, value), hash|
95
131
  hash[key.to_sym] = value.is_a?(Hash) ? deep_symbolize(value) : value
96
132
  end
97
- hash
98
133
  end
99
134
 
100
135
  def options_for(option)
101
136
  hash = {}
102
137
  options.send(:"#{option}_options").select { |key| options[key] }.each do |key|
103
- hash[key.to_sym] = options[key]
138
+ hash[key.to_sym] = if options[key].respond_to?(:call)
139
+ options[key].call(env)
140
+ else
141
+ options[key]
142
+ end
104
143
  end
105
144
  hash
106
145
  end
@@ -3,22 +3,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "omniauth-oauth2/version"
4
4
 
5
5
  Gem::Specification.new do |gem|
6
- gem.add_dependency "oauth2", "~> 1.0"
7
- gem.add_dependency "omniauth", "~> 1.2"
6
+ gem.add_dependency "oauth2", "~> 1.4"
7
+ gem.add_dependency "omniauth", "~> 1.9"
8
8
 
9
- gem.add_development_dependency "bundler", "~> 1.0"
9
+ gem.add_development_dependency "bundler", "~> 2.0"
10
10
 
11
- gem.authors = ["Michael Bleigh", "Erik Michaels-Ober"]
12
- gem.email = ["michael@intridea.com", "sferik@gmail.com"]
11
+ gem.authors = ["Michael Bleigh", "Erik Michaels-Ober", "Tom Milewski"]
12
+ gem.email = ["michael@intridea.com", "sferik@gmail.com", "tmilewski@gmail.com"]
13
13
  gem.description = "An abstract OAuth2 strategy for OmniAuth."
14
14
  gem.summary = gem.description
15
- gem.homepage = "https://github.com/intridea/omniauth-oauth2"
16
- gem.licenses = %w(MIT)
15
+ gem.homepage = "https://github.com/omniauth/omniauth-oauth2"
16
+ gem.licenses = %w[MIT]
17
17
 
18
18
  gem.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) }
19
19
  gem.files = `git ls-files`.split("\n")
20
20
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
21
  gem.name = "omniauth-oauth2"
22
- gem.require_paths = %w(lib)
22
+ gem.require_paths = %w[lib]
23
23
  gem.version = OmniAuth::OAuth2::VERSION
24
24
  end
@@ -16,6 +16,15 @@ describe OmniAuth::Strategies::OAuth2 do
16
16
  OmniAuth.config.test_mode = false
17
17
  end
18
18
 
19
+ describe "Subclassing Behavior" do
20
+ subject { fresh_strategy }
21
+
22
+ it "performs the OmniAuth::Strategy included hook" do
23
+ expect(OmniAuth.strategies).to include(OmniAuth::Strategies::OAuth2)
24
+ expect(OmniAuth.strategies).to include(subject)
25
+ end
26
+ end
27
+
19
28
  describe "#client" do
20
29
  subject { fresh_strategy }
21
30
 
@@ -40,9 +49,10 @@ describe OmniAuth::Strategies::OAuth2 do
40
49
  end
41
50
 
42
51
  it "includes top-level options that are marked as :authorize_options" do
43
- instance = subject.new("abc", "def", :authorize_options => [:scope, :foo, :state], :scope => "bar", :foo => "baz")
52
+ instance = subject.new("abc", "def", :authorize_options => %i[scope foo state], :scope => "bar", :foo => "baz")
44
53
  expect(instance.authorize_params["scope"]).to eq("bar")
45
54
  expect(instance.authorize_params["foo"]).to eq("baz")
55
+ expect(instance.authorize_params["state"]).not_to be_empty
46
56
  end
47
57
 
48
58
  it "includes random state in the authorize params" do
@@ -50,6 +60,19 @@ describe OmniAuth::Strategies::OAuth2 do
50
60
  expect(instance.authorize_params.keys).to eq(["state"])
51
61
  expect(instance.session["omniauth.state"]).not_to be_empty
52
62
  end
63
+
64
+ it "includes custom state in the authorize params" do
65
+ instance = subject.new("abc", "def", :state => proc { "qux" })
66
+ expect(instance.authorize_params.keys).to eq(["state"])
67
+ expect(instance.session["omniauth.state"]).to eq("qux")
68
+ end
69
+
70
+ it "includes PKCE parameters if enabled" do
71
+ instance = subject.new("abc", "def", :pkce => true)
72
+ expect(instance.authorize_params[:code_challenge]).to be_a(String)
73
+ expect(instance.authorize_params[:code_challenge_method]).to eq("S256")
74
+ expect(instance.session["omniauth.pkce.verifier"]).to be_a(String)
75
+ end
53
76
  end
54
77
 
55
78
  describe "#token_params" do
@@ -61,9 +84,16 @@ describe OmniAuth::Strategies::OAuth2 do
61
84
  end
62
85
 
63
86
  it "includes top-level options that are marked as :authorize_options" do
64
- instance = subject.new("abc", "def", :token_options => [:scope, :foo], :scope => "bar", :foo => "baz")
87
+ instance = subject.new("abc", "def", :token_options => %i[scope foo], :scope => "bar", :foo => "baz")
65
88
  expect(instance.token_params).to eq("scope" => "bar", "foo" => "baz")
66
89
  end
90
+
91
+ it "includes the PKCE code_verifier if enabled" do
92
+ instance = subject.new("abc", "def", :pkce => true)
93
+ # setup session
94
+ instance.authorize_params
95
+ expect(instance.token_params[:code_verifier]).to be_a(String)
96
+ end
67
97
  end
68
98
 
69
99
  describe "#callback_phase" do
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
8
8
  - Erik Michaels-Ober
9
+ - Tom Milewski
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2015-04-22 00:00:00.000000000 Z
13
+ date: 2020-08-11 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: oauth2
@@ -17,46 +18,47 @@ dependencies:
17
18
  requirements:
18
19
  - - "~>"
19
20
  - !ruby/object:Gem::Version
20
- version: '1.0'
21
+ version: '1.4'
21
22
  type: :runtime
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  requirements:
25
26
  - - "~>"
26
27
  - !ruby/object:Gem::Version
27
- version: '1.0'
28
+ version: '1.4'
28
29
  - !ruby/object:Gem::Dependency
29
30
  name: omniauth
30
31
  requirement: !ruby/object:Gem::Requirement
31
32
  requirements:
32
33
  - - "~>"
33
34
  - !ruby/object:Gem::Version
34
- version: '1.2'
35
+ version: '1.9'
35
36
  type: :runtime
36
37
  prerelease: false
37
38
  version_requirements: !ruby/object:Gem::Requirement
38
39
  requirements:
39
40
  - - "~>"
40
41
  - !ruby/object:Gem::Version
41
- version: '1.2'
42
+ version: '1.9'
42
43
  - !ruby/object:Gem::Dependency
43
44
  name: bundler
44
45
  requirement: !ruby/object:Gem::Requirement
45
46
  requirements:
46
47
  - - "~>"
47
48
  - !ruby/object:Gem::Version
48
- version: '1.0'
49
+ version: '2.0'
49
50
  type: :development
50
51
  prerelease: false
51
52
  version_requirements: !ruby/object:Gem::Requirement
52
53
  requirements:
53
54
  - - "~>"
54
55
  - !ruby/object:Gem::Version
55
- version: '1.0'
56
+ version: '2.0'
56
57
  description: An abstract OAuth2 strategy for OmniAuth.
57
58
  email:
58
59
  - michael@intridea.com
59
60
  - sferik@gmail.com
61
+ - tmilewski@gmail.com
60
62
  executables: []
61
63
  extensions: []
62
64
  extra_rdoc_files: []
@@ -75,7 +77,7 @@ files:
75
77
  - omniauth-oauth2.gemspec
76
78
  - spec/helper.rb
77
79
  - spec/omniauth/strategies/oauth2_spec.rb
78
- homepage: https://github.com/intridea/omniauth-oauth2
80
+ homepage: https://github.com/omniauth/omniauth-oauth2
79
81
  licenses:
80
82
  - MIT
81
83
  metadata: {}
@@ -94,8 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
96
  - !ruby/object:Gem::Version
95
97
  version: '0'
96
98
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.4.5
99
+ rubygems_version: 3.0.0
99
100
  signing_key:
100
101
  specification_version: 4
101
102
  summary: An abstract OAuth2 strategy for OmniAuth.