omniauth-oauth2 1.1.1 → 1.1.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 +7 -0
- data/.rubocop.yml +78 -0
- data/.travis.yml +27 -0
- data/Gemfile +27 -8
- data/LICENSE.md +19 -0
- data/README.md +55 -62
- data/Rakefile +14 -5
- data/lib/omniauth-oauth2.rb +1 -1
- data/lib/omniauth-oauth2/version.rb +1 -1
- data/lib/omniauth/strategies/oauth2.rb +42 -27
- data/omniauth-oauth2.gemspec +16 -15
- data/spec/helper.rb +28 -0
- data/spec/omniauth/strategies/oauth2_spec.rb +57 -22
- metadata +53 -68
- data/spec/spec_helper.rb +0 -16
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 729f67df8ee052a37b39db77bb84fc0e954b5c47
|
4
|
+
data.tar.gz: 03e11773729ff900ad4edb07be8c8e13fc001316
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e17fffddb77d20eb90a87b88974e8d65a48fe07b8efb6c193bcac18cd51320ffbc253f1c78a47ed07fb59b70049d632a583580940215a11d27f1160c466c8de
|
7
|
+
data.tar.gz: 630038ac3b8270b536dfed054e3a26a9ba7de3bfd5d563a8e0ff094154431fc6b322ad27d573ce3fbe5a7f2c8bd907e2cd1382eda42587d777037e4b2d58b8aa
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
AllCops:
|
2
|
+
Includes:
|
3
|
+
- 'Gemfile'
|
4
|
+
- 'Rakefile'
|
5
|
+
- 'omniauth-oauth2.gemspec'
|
6
|
+
|
7
|
+
# Avoid long parameter lists
|
8
|
+
ParameterLists:
|
9
|
+
Max: 5
|
10
|
+
CountKeywordArgs: true
|
11
|
+
|
12
|
+
MethodLength:
|
13
|
+
CountComments: false
|
14
|
+
Max: 18
|
15
|
+
|
16
|
+
# Avoid more than `Max` levels of nesting.
|
17
|
+
BlockNesting:
|
18
|
+
Max: 2
|
19
|
+
|
20
|
+
# Align with the style guide.
|
21
|
+
CollectionMethods:
|
22
|
+
PreferredMethods:
|
23
|
+
map: 'collect'
|
24
|
+
reduce: 'inject'
|
25
|
+
find: 'detect'
|
26
|
+
find_all: 'select'
|
27
|
+
|
28
|
+
# Do not force public/protected/private keyword to be indented at the same
|
29
|
+
# level as the def keyword. My personal preference is to outdent these keywords
|
30
|
+
# because I think when scanning code it makes it easier to identify the
|
31
|
+
# sections of code and visually separate them. When the keyword is at the same
|
32
|
+
# level I think it sort of blends in with the def keywords and makes it harder
|
33
|
+
# to scan the code and see where the sections are.
|
34
|
+
AccessModifierIndentation:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
# Limit line length
|
38
|
+
LineLength:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
# Disable documentation checking until a class needs to be documented once
|
42
|
+
Documentation:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
# Enforce Ruby 1.8-compatible hash syntax
|
46
|
+
HashSyntax:
|
47
|
+
EnforcedStyle: hash_rockets
|
48
|
+
|
49
|
+
# No spaces inside hash literals
|
50
|
+
SpaceInsideHashLiteralBraces:
|
51
|
+
EnforcedStyle: no_space
|
52
|
+
|
53
|
+
# Allow dots at the end of lines
|
54
|
+
DotPosition:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
# Don't require magic comment at the top of every file
|
58
|
+
Encoding:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
# Enforce outdenting of access modifiers (i.e. public, private, protected)
|
62
|
+
AccessModifierIndentation:
|
63
|
+
EnforcedStyle: outdent
|
64
|
+
|
65
|
+
EmptyLinesAroundAccessModifier:
|
66
|
+
Enabled: true
|
67
|
+
|
68
|
+
# Align ends correctly
|
69
|
+
EndAlignment:
|
70
|
+
AlignWith: variable
|
71
|
+
|
72
|
+
# Indentation of when/else
|
73
|
+
CaseIndentation:
|
74
|
+
IndentWhenRelativeTo: end
|
75
|
+
IndentOneStep: false
|
76
|
+
|
77
|
+
Lambda:
|
78
|
+
Enabled: false
|
data/.travis.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
before_install:
|
2
|
+
- gem install bundler
|
3
|
+
- bundle --version
|
4
|
+
- gem update --system 2.1.11
|
5
|
+
- gem --version
|
6
|
+
bundler_args: --without development
|
7
|
+
language: ruby
|
8
|
+
rvm:
|
9
|
+
- 1.8.7
|
10
|
+
- 1.9.2
|
11
|
+
- 1.9.3
|
12
|
+
- 2.0.0
|
13
|
+
- 2.1.0
|
14
|
+
- rbx
|
15
|
+
- ruby-head
|
16
|
+
matrix:
|
17
|
+
include:
|
18
|
+
- rvm: jruby-18mode
|
19
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
20
|
+
- rvm: jruby-19mode
|
21
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
22
|
+
- rvm: jruby-head
|
23
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
24
|
+
allow_failures:
|
25
|
+
- rvm: jruby-head
|
26
|
+
- rvm: ruby-head
|
27
|
+
fast_finish: true
|
data/Gemfile
CHANGED
@@ -1,12 +1,31 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
gemspec
|
3
|
+
gem 'rake'
|
5
4
|
|
6
|
-
group :development
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
group :development do
|
6
|
+
platforms :ruby_19, :ruby_20, :ruby_21 do
|
7
|
+
gem 'guard'
|
8
|
+
gem 'guard-rspec'
|
9
|
+
gem 'guard-bundler'
|
10
|
+
end
|
12
11
|
end
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem 'coveralls', :require => false
|
15
|
+
gem 'json', :platforms => [:jruby, :rbx, :ruby_18, :ruby_19]
|
16
|
+
gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18]
|
17
|
+
gem 'rack-test'
|
18
|
+
gem 'rspec', '~> 2.14'
|
19
|
+
gem 'rubocop', '>= 0.16', :platforms => [:ruby_19, :ruby_20, :ruby_21]
|
20
|
+
gem 'simplecov', :require => false
|
21
|
+
gem 'webmock'
|
22
|
+
end
|
23
|
+
|
24
|
+
platforms :rbx do
|
25
|
+
gem 'racc'
|
26
|
+
gem 'rubinius-coverage', '~> 2.0'
|
27
|
+
gem 'rubysl', '~> 2.0'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify your gem's dependencies in omniauth-oauth2.gemspec
|
31
|
+
gemspec
|
data/LICENSE.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2014 Michael Bleigh, Erik Michaels-Ober and Intridea, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,74 +1,67 @@
|
|
1
1
|
# OmniAuth OAuth2
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
[][gem]
|
4
|
+
[][travis]
|
5
|
+
[][gemnasium]
|
6
|
+
[][codeclimate]
|
7
|
+
[][coveralls]
|
8
|
+
|
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
|
12
|
+
[codeclimate]: https://codeclimate.com/github/intridea/omniauth-oauth2
|
13
|
+
[coveralls]: https://coveralls.io/r/intridea/omniauth-oauth2
|
14
|
+
|
15
|
+
This gem contains a generic OAuth2 strategy for OmniAuth. It is meant to serve
|
16
|
+
as a building block strategy for other strategies and not to be used
|
17
|
+
independently (since it has no inherent way to gather uid and user info).
|
7
18
|
|
8
19
|
## Creating an OAuth2 Strategy
|
9
20
|
|
10
|
-
To create an OmniAuth OAuth2 strategy using this gem, you can simply
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
21
|
+
To create an OmniAuth OAuth2 strategy using this gem, you can simply subclass
|
22
|
+
it and add a few extra methods like so:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'omniauth-oauth2'
|
26
|
+
|
27
|
+
module OmniAuth
|
28
|
+
module Strategies
|
29
|
+
class SomeSite < OmniAuth::Strategies::OAuth2
|
30
|
+
# Give your strategy a name.
|
31
|
+
option :name, "some_site"
|
32
|
+
|
33
|
+
# This is where you pass the options you would pass when
|
34
|
+
# initializing your consumer from the OAuth gem.
|
35
|
+
option :client_options, {:site => "https://api.somesite.com"}
|
36
|
+
|
37
|
+
# These are called after authentication has succeeded. If
|
38
|
+
# possible, you should try to set the UID without making
|
39
|
+
# additional calls (if the user id is returned with the token
|
40
|
+
# or as a URI parameter). This may not be possible with all
|
41
|
+
# providers.
|
42
|
+
uid{ raw_info['id'] }
|
43
|
+
|
44
|
+
info do
|
45
|
+
{
|
46
|
+
:name => raw_info['name'],
|
47
|
+
:email => raw_info['email']
|
48
|
+
}
|
49
|
+
end
|
38
50
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
51
|
+
extra do
|
52
|
+
{
|
53
|
+
'raw_info' => raw_info
|
54
|
+
}
|
55
|
+
end
|
44
56
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
57
|
+
def raw_info
|
58
|
+
@raw_info ||= access_token.get('/me').parsed
|
49
59
|
end
|
50
60
|
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
51
64
|
|
52
65
|
That's pretty much it!
|
53
66
|
|
54
|
-
|
55
|
-
|
56
|
-
Copyright (C) 2011 by Michael Bleigh and Intridea, Inc.
|
57
|
-
|
58
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
59
|
-
of this software and associated documentation files (the "Software"), to deal
|
60
|
-
in the Software without restriction, including without limitation the rights
|
61
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
62
|
-
copies of the Software, and to permit persons to whom the Software is
|
63
|
-
furnished to do so, subject to the following conditions:
|
64
|
-
|
65
|
-
The above copyright notice and this permission notice shall be included in
|
66
|
-
all copies or substantial portions of the Software.
|
67
|
-
|
68
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
69
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
70
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
71
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
72
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
73
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
74
|
-
THE SOFTWARE.
|
67
|
+
[](https://bitdeli.com/free "Bitdeli Badge")
|
data/Rakefile
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
2
|
+
require 'bundler/gem_tasks'
|
3
3
|
require 'rspec/core/rake_task'
|
4
4
|
|
5
|
-
desc 'Default: run specs.'
|
6
|
-
task :default => :spec
|
7
|
-
|
8
|
-
desc "Run specs"
|
9
5
|
RSpec::Core::RakeTask.new
|
6
|
+
|
7
|
+
task :test => :spec
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'rubocop/rake_task'
|
11
|
+
Rubocop::RakeTask.new
|
12
|
+
rescue LoadError
|
13
|
+
task :rubocop do
|
14
|
+
$stderr.puts 'Rubocop is disabled'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => [:spec, :rubocop]
|
data/lib/omniauth-oauth2.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
1
|
+
require 'omniauth-oauth2/version'
|
2
2
|
require 'omniauth/strategies/oauth2'
|
@@ -1,9 +1,10 @@
|
|
1
|
-
require 'cgi'
|
2
|
-
require 'uri'
|
3
1
|
require 'oauth2'
|
4
2
|
require 'omniauth'
|
5
|
-
require 'timeout'
|
6
3
|
require 'securerandom'
|
4
|
+
require 'socket' # for SocketError
|
5
|
+
require 'timeout' # for Timeout::Error
|
6
|
+
require 'faraday' # for Faraday::Error::TimeoutError and Faraday::Error::ConnectionFailed
|
7
|
+
require 'multi_json' # for MultiJson::DecodeError
|
7
8
|
|
8
9
|
module OmniAuth
|
9
10
|
module Strategies
|
@@ -24,6 +25,7 @@ module OmniAuth
|
|
24
25
|
option :authorize_options, [:scope]
|
25
26
|
option :token_params, {}
|
26
27
|
option :token_options, []
|
28
|
+
option :auth_token_params, {}
|
27
29
|
option :provider_ignores_state, false
|
28
30
|
|
29
31
|
attr_accessor :access_token
|
@@ -50,7 +52,7 @@ module OmniAuth
|
|
50
52
|
|
51
53
|
def authorize_params
|
52
54
|
options.authorize_params[:state] = SecureRandom.hex(24)
|
53
|
-
params = options.authorize_params.merge(
|
55
|
+
params = options.authorize_params.merge(options_for('authorize'))
|
54
56
|
if OmniAuth.config.test_mode
|
55
57
|
@env ||= {}
|
56
58
|
@env['rack.session'] ||= {}
|
@@ -60,43 +62,51 @@ module OmniAuth
|
|
60
62
|
end
|
61
63
|
|
62
64
|
def token_params
|
63
|
-
options.token_params.merge(
|
65
|
+
options.token_params.merge(options_for('token'))
|
64
66
|
end
|
65
67
|
|
66
|
-
def callback_phase
|
67
|
-
|
68
|
-
|
68
|
+
def callback_phase # rubocop:disable CyclomaticComplexity
|
69
|
+
error = request.params['error_reason'] || request.params['error']
|
70
|
+
if error
|
71
|
+
fail!(error, CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri']))
|
72
|
+
elsif !options.provider_ignores_state && (request.params['state'].to_s.empty? || request.params['state'] != session.delete('omniauth.state'))
|
73
|
+
fail!(:csrf_detected, CallbackError.new(:csrf_detected, 'CSRF detected'))
|
74
|
+
else
|
75
|
+
self.access_token = build_access_token
|
76
|
+
self.access_token = access_token.refresh! if access_token.expired?
|
77
|
+
super
|
69
78
|
end
|
70
|
-
if !options.provider_ignores_state && (request.params['state'].to_s.empty? || request.params['state'] != session.delete('omniauth.state'))
|
71
|
-
raise CallbackError.new(nil, :csrf_detected)
|
72
|
-
end
|
73
|
-
|
74
|
-
self.access_token = build_access_token
|
75
|
-
self.access_token = access_token.refresh! if access_token.expired?
|
76
|
-
|
77
|
-
super
|
78
79
|
rescue ::OAuth2::Error, CallbackError => e
|
79
80
|
fail!(:invalid_credentials, e)
|
80
81
|
rescue ::MultiJson::DecodeError => e
|
81
82
|
fail!(:invalid_response, e)
|
82
|
-
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
|
83
|
+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT, Faraday::Error::TimeoutError => e
|
83
84
|
fail!(:timeout, e)
|
84
|
-
rescue ::SocketError => e
|
85
|
+
rescue ::SocketError, Faraday::Error::ConnectionFailed => e
|
85
86
|
fail!(:failed_to_connect, e)
|
86
87
|
end
|
87
88
|
|
88
|
-
|
89
|
+
protected
|
90
|
+
|
91
|
+
def build_access_token
|
92
|
+
verifier = request.params['code']
|
93
|
+
client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params))
|
94
|
+
end
|
89
95
|
|
90
|
-
def deep_symbolize(
|
91
|
-
hash
|
92
|
-
|
93
|
-
|
96
|
+
def deep_symbolize(options)
|
97
|
+
hash = {}
|
98
|
+
options.each do |key, value|
|
99
|
+
hash[key.to_sym] = value.is_a?(Hash) ? deep_symbolize(value) : value
|
94
100
|
end
|
101
|
+
hash
|
95
102
|
end
|
96
103
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
104
|
+
def options_for(option)
|
105
|
+
hash = {}
|
106
|
+
options.send(:"#{option}_options").select { |key| options[key] }.each do |key|
|
107
|
+
hash[key.to_sym] = options[key]
|
108
|
+
end
|
109
|
+
hash
|
100
110
|
end
|
101
111
|
|
102
112
|
# An error that is indicated in the OAuth 2.0 callback.
|
@@ -104,13 +114,18 @@ module OmniAuth
|
|
104
114
|
class CallbackError < StandardError
|
105
115
|
attr_accessor :error, :error_reason, :error_uri
|
106
116
|
|
107
|
-
def initialize(error, error_reason=nil, error_uri=nil)
|
117
|
+
def initialize(error, error_reason = nil, error_uri = nil)
|
108
118
|
self.error = error
|
109
119
|
self.error_reason = error_reason
|
110
120
|
self.error_uri = error_uri
|
111
121
|
end
|
122
|
+
|
123
|
+
def message
|
124
|
+
[error, error_reason, error_uri].compact.join(' | ')
|
125
|
+
end
|
112
126
|
end
|
113
127
|
end
|
114
128
|
end
|
115
129
|
end
|
130
|
+
|
116
131
|
OmniAuth.config.add_camelization 'oauth2', 'OAuth2'
|
data/omniauth-oauth2.gemspec
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'omniauth-oauth2/version'
|
3
4
|
|
4
5
|
Gem::Specification.new do |gem|
|
5
|
-
gem.add_dependency '
|
6
|
-
gem.add_dependency '
|
6
|
+
gem.add_dependency 'faraday', ['>= 0.8', '< 0.10']
|
7
|
+
gem.add_dependency 'multi_json', '~> 1.3'
|
8
|
+
gem.add_dependency 'oauth2', '~> 0.9.3'
|
9
|
+
gem.add_dependency 'omniauth', '~> 1.2'
|
7
10
|
|
8
|
-
gem.add_development_dependency '
|
9
|
-
gem.add_development_dependency 'rack-test'
|
10
|
-
gem.add_development_dependency 'webmock'
|
11
|
-
gem.add_development_dependency 'simplecov'
|
11
|
+
gem.add_development_dependency 'bundler', '~> 1.0'
|
12
12
|
|
13
|
-
gem.authors = [
|
14
|
-
gem.email = [
|
13
|
+
gem.authors = ['Michael Bleigh', 'Erik Michaels-Ober']
|
14
|
+
gem.email = ['michael@intridea.com', 'sferik@gmail.com']
|
15
15
|
gem.description = %q{An abstract OAuth2 strategy for OmniAuth.}
|
16
|
-
gem.summary =
|
17
|
-
gem.homepage =
|
16
|
+
gem.summary = gem.description
|
17
|
+
gem.homepage = 'https://github.com/intridea/omniauth-oauth2'
|
18
|
+
gem.license = 'MIT'
|
18
19
|
|
19
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").
|
20
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) }
|
20
21
|
gem.files = `git ls-files`.split("\n")
|
21
22
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
-
gem.name =
|
23
|
-
gem.require_paths = [
|
23
|
+
gem.name = 'omniauth-oauth2'
|
24
|
+
gem.require_paths = ['lib']
|
24
25
|
gem.version = OmniAuth::OAuth2::VERSION
|
25
26
|
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
require 'coveralls'
|
6
|
+
|
7
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
8
|
+
SimpleCov::Formatter::HTMLFormatter,
|
9
|
+
Coveralls::SimpleCov::Formatter
|
10
|
+
]
|
11
|
+
SimpleCov.start do
|
12
|
+
minimum_coverage(76)
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'rspec'
|
16
|
+
require 'rack/test'
|
17
|
+
require 'webmock/rspec'
|
18
|
+
require 'omniauth'
|
19
|
+
require 'omniauth-oauth2'
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
config.expect_with :rspec do |c|
|
23
|
+
c.syntax = :expect
|
24
|
+
end
|
25
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
26
|
+
config.include Rack::Test::Methods
|
27
|
+
config.include WebMock::API
|
28
|
+
end
|
@@ -1,8 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
describe OmniAuth::Strategies::OAuth2 do
|
4
|
-
def app
|
5
|
-
|
4
|
+
def app
|
5
|
+
lambda do |env|
|
6
|
+
[200, {}, ['Hello.']]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
let(:fresh_strategy) { Class.new(OmniAuth::Strategies::OAuth2) }
|
6
10
|
|
7
11
|
before do
|
8
12
|
OmniAuth.config.test_mode = true
|
@@ -13,51 +17,82 @@ describe OmniAuth::Strategies::OAuth2 do
|
|
13
17
|
end
|
14
18
|
|
15
19
|
describe '#client' do
|
16
|
-
subject{ fresh_strategy }
|
20
|
+
subject { fresh_strategy }
|
17
21
|
|
18
|
-
it '
|
22
|
+
it 'is initialized with symbolized client_options' do
|
19
23
|
instance = subject.new(app, :client_options => {'authorize_url' => 'https://example.com'})
|
20
|
-
instance.client.options[:authorize_url].
|
24
|
+
expect(instance.client.options[:authorize_url]).to eq('https://example.com')
|
21
25
|
end
|
22
26
|
|
23
|
-
it '
|
27
|
+
it 'sets ssl options as connection options' do
|
24
28
|
instance = subject.new(app, :client_options => {'ssl' => {'ca_path' => 'foo'}})
|
25
|
-
instance.client.options[:connection_opts][:ssl]
|
29
|
+
expect(instance.client.options[:connection_opts][:ssl]).to eq(:ca_path => 'foo')
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
29
33
|
describe '#authorize_params' do
|
30
34
|
subject { fresh_strategy }
|
31
35
|
|
32
|
-
it '
|
33
|
-
instance = subject.new('abc', 'def', :authorize_params => {:foo => 'bar', :baz => 'zip'
|
34
|
-
instance.authorize_params
|
36
|
+
it 'includes any authorize params passed in the :authorize_params option' do
|
37
|
+
instance = subject.new('abc', 'def', :authorize_params => {:foo => 'bar', :baz => 'zip'})
|
38
|
+
expect(instance.authorize_params['foo']).to eq('bar')
|
39
|
+
expect(instance.authorize_params['baz']).to eq('zip')
|
35
40
|
end
|
36
41
|
|
37
|
-
it '
|
38
|
-
instance = subject.new('abc', 'def', :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz'
|
39
|
-
instance.authorize_params
|
42
|
+
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')
|
44
|
+
expect(instance.authorize_params['scope']).to eq('bar')
|
45
|
+
expect(instance.authorize_params['foo']).to eq('baz')
|
40
46
|
end
|
41
47
|
|
42
|
-
it '
|
48
|
+
it 'includes random state in the authorize params' do
|
43
49
|
instance = subject.new('abc', 'def')
|
44
|
-
instance.authorize_params.keys.
|
45
|
-
instance.session['omniauth.state'].
|
46
|
-
instance.session['omniauth.state'].should == instance.authorize_params['state']
|
50
|
+
expect(instance.authorize_params.keys).to eq(['state'])
|
51
|
+
expect(instance.session['omniauth.state']).not_to be_empty
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
50
55
|
describe '#token_params' do
|
51
56
|
subject { fresh_strategy }
|
52
57
|
|
53
|
-
it '
|
58
|
+
it 'includes any authorize params passed in the :authorize_params option' do
|
54
59
|
instance = subject.new('abc', 'def', :token_params => {:foo => 'bar', :baz => 'zip'})
|
55
|
-
instance.token_params.
|
60
|
+
expect(instance.token_params).to eq('foo' => 'bar', 'baz' => 'zip')
|
56
61
|
end
|
57
62
|
|
58
|
-
it '
|
63
|
+
it 'includes top-level options that are marked as :authorize_options' do
|
59
64
|
instance = subject.new('abc', 'def', :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz')
|
60
|
-
instance.token_params.
|
65
|
+
expect(instance.token_params).to eq('scope' => 'bar', 'foo' => 'baz')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#callback_phase' do
|
70
|
+
subject { fresh_strategy }
|
71
|
+
it 'calls fail with the client error received' do
|
72
|
+
instance = subject.new('abc', 'def')
|
73
|
+
instance.stub(:request) do
|
74
|
+
double('Request', :params => {'error_reason' => 'user_denied', 'error' => 'access_denied'})
|
75
|
+
end
|
76
|
+
|
77
|
+
expect(instance).to receive(:fail!).with('user_denied', anything)
|
78
|
+
instance.callback_phase
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe OmniAuth::Strategies::OAuth2::CallbackError do
|
84
|
+
let(:error) { Class.new(OmniAuth::Strategies::OAuth2::CallbackError) }
|
85
|
+
describe '#message' do
|
86
|
+
subject { error }
|
87
|
+
it 'includes all of the attributes' do
|
88
|
+
instance = subject.new('error', 'description', 'uri')
|
89
|
+
expect(instance.message).to match(/error/)
|
90
|
+
expect(instance.message).to match(/description/)
|
91
|
+
expect(instance.message).to match(/uri/)
|
92
|
+
end
|
93
|
+
it 'includes all of the attributes' do
|
94
|
+
instance = subject.new(nil, :symbol)
|
95
|
+
expect(instance.message).to eq('symbol')
|
61
96
|
end
|
62
97
|
end
|
63
98
|
end
|
metadata
CHANGED
@@ -1,154 +1,139 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Michael Bleigh
|
8
|
+
- Erik Michaels-Ober
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: faraday
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '1.0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
17
|
requirements:
|
27
|
-
- -
|
18
|
+
- - ">="
|
28
19
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
30
|
-
-
|
31
|
-
name: oauth2
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
20
|
+
version: '0.8'
|
21
|
+
- - "<"
|
36
22
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
23
|
+
version: '0.10'
|
38
24
|
type: :runtime
|
39
25
|
prerelease: false
|
40
26
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
27
|
requirements:
|
43
|
-
- -
|
28
|
+
- - ">="
|
44
29
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.8
|
30
|
+
version: '0.8'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.10'
|
46
34
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
35
|
+
name: multi_json
|
48
36
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
37
|
requirements:
|
51
|
-
- - ~>
|
38
|
+
- - "~>"
|
52
39
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
54
|
-
type: :
|
40
|
+
version: '1.3'
|
41
|
+
type: :runtime
|
55
42
|
prerelease: false
|
56
43
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
44
|
requirements:
|
59
|
-
- - ~>
|
45
|
+
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
47
|
+
version: '1.3'
|
62
48
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
49
|
+
name: oauth2
|
64
50
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
51
|
requirements:
|
67
|
-
- -
|
52
|
+
- - "~>"
|
68
53
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
70
|
-
type: :
|
54
|
+
version: 0.9.3
|
55
|
+
type: :runtime
|
71
56
|
prerelease: false
|
72
57
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
58
|
requirements:
|
75
|
-
- -
|
59
|
+
- - "~>"
|
76
60
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
61
|
+
version: 0.9.3
|
78
62
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
63
|
+
name: omniauth
|
80
64
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
65
|
requirements:
|
83
|
-
- -
|
66
|
+
- - "~>"
|
84
67
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
86
|
-
type: :
|
68
|
+
version: '1.2'
|
69
|
+
type: :runtime
|
87
70
|
prerelease: false
|
88
71
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
72
|
requirements:
|
91
|
-
- -
|
73
|
+
- - "~>"
|
92
74
|
- !ruby/object:Gem::Version
|
93
|
-
version: '
|
75
|
+
version: '1.2'
|
94
76
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
77
|
+
name: bundler
|
96
78
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
79
|
requirements:
|
99
|
-
- -
|
80
|
+
- - "~>"
|
100
81
|
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
82
|
+
version: '1.0'
|
102
83
|
type: :development
|
103
84
|
prerelease: false
|
104
85
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
86
|
requirements:
|
107
|
-
- -
|
87
|
+
- - "~>"
|
108
88
|
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
89
|
+
version: '1.0'
|
110
90
|
description: An abstract OAuth2 strategy for OmniAuth.
|
111
91
|
email:
|
112
92
|
- michael@intridea.com
|
93
|
+
- sferik@gmail.com
|
113
94
|
executables: []
|
114
95
|
extensions: []
|
115
96
|
extra_rdoc_files: []
|
116
97
|
files:
|
117
|
-
- .gitignore
|
118
|
-
- .rspec
|
98
|
+
- ".gitignore"
|
99
|
+
- ".rspec"
|
100
|
+
- ".rubocop.yml"
|
101
|
+
- ".travis.yml"
|
119
102
|
- Gemfile
|
120
103
|
- Guardfile
|
104
|
+
- LICENSE.md
|
121
105
|
- README.md
|
122
106
|
- Rakefile
|
123
107
|
- lib/omniauth-oauth2.rb
|
124
108
|
- lib/omniauth-oauth2/version.rb
|
125
109
|
- lib/omniauth/strategies/oauth2.rb
|
126
110
|
- omniauth-oauth2.gemspec
|
111
|
+
- spec/helper.rb
|
127
112
|
- spec/omniauth/strategies/oauth2_spec.rb
|
128
|
-
- spec/spec_helper.rb
|
129
113
|
homepage: https://github.com/intridea/omniauth-oauth2
|
130
|
-
licenses:
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
131
117
|
post_install_message:
|
132
118
|
rdoc_options: []
|
133
119
|
require_paths:
|
134
120
|
- lib
|
135
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
-
none: false
|
137
122
|
requirements:
|
138
|
-
- -
|
123
|
+
- - ">="
|
139
124
|
- !ruby/object:Gem::Version
|
140
125
|
version: '0'
|
141
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
-
none: false
|
143
127
|
requirements:
|
144
|
-
- -
|
128
|
+
- - ">="
|
145
129
|
- !ruby/object:Gem::Version
|
146
130
|
version: '0'
|
147
131
|
requirements: []
|
148
132
|
rubyforge_project:
|
149
|
-
rubygems_version:
|
133
|
+
rubygems_version: 2.2.0
|
150
134
|
signing_key:
|
151
|
-
specification_version:
|
135
|
+
specification_version: 4
|
152
136
|
summary: An abstract OAuth2 strategy for OmniAuth.
|
153
|
-
test_files:
|
154
|
-
|
137
|
+
test_files:
|
138
|
+
- spec/helper.rb
|
139
|
+
- spec/omniauth/strategies/oauth2_spec.rb
|
data/spec/spec_helper.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
$:.unshift File.expand_path('..', __FILE__)
|
2
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
-
require 'simplecov'
|
4
|
-
SimpleCov.start
|
5
|
-
require 'rspec'
|
6
|
-
require 'rack/test'
|
7
|
-
require 'webmock/rspec'
|
8
|
-
require 'omniauth'
|
9
|
-
require 'omniauth-oauth2'
|
10
|
-
|
11
|
-
RSpec.configure do |config|
|
12
|
-
config.include WebMock::API
|
13
|
-
config.include Rack::Test::Methods
|
14
|
-
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
15
|
-
end
|
16
|
-
|