peentar-omniauth-oauth2 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rubocop.yml +42 -0
- data/.travis.yml +22 -0
- data/Gemfile +18 -0
- data/LICENSE.md +20 -0
- data/README.md +69 -0
- data/Rakefile +20 -0
- data/lib/omniauth/strategies/oauth2.rb +127 -0
- data/lib/omniauth-oauth2/version.rb +5 -0
- data/lib/omniauth-oauth2.rb +2 -0
- data/omniauth-oauth2.gemspec +25 -0
- data/spec/helper.rb +28 -0
- data/spec/omniauth/strategies/oauth2_spec.rb +107 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 844106135be7aff902fe1654e590c365f0746229
|
4
|
+
data.tar.gz: 9bfd8a8110bae177b6d4c53010d691862bb1a44a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a35b474040de277f6ba7b4b2cf8b9a1bc1cac636cb1f8230852a65f64ae949814b1bd0cf3797749ec39b6d0ca497c5366adca58fe33ffc57664e59a0dab2450e
|
7
|
+
data.tar.gz: 952d5415da54721926ec90464cc6a347c5b4ee6ab8e611c5c2e22c3e1f0072f42a8bf04bb9e7e545a8578aa62e9eb2e5cc44de3bcb0b770bed523d74ae4b34c3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Metrics/BlockNesting:
|
2
|
+
Max: 2
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
AllowURI: true
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Metrics/MethodLength:
|
9
|
+
CountComments: false
|
10
|
+
Max: 10
|
11
|
+
|
12
|
+
Metrics/ParameterLists:
|
13
|
+
Max: 4
|
14
|
+
CountKeywordArgs: true
|
15
|
+
|
16
|
+
Style/AccessModifierIndentation:
|
17
|
+
EnforcedStyle: outdent
|
18
|
+
|
19
|
+
Style/CollectionMethods:
|
20
|
+
PreferredMethods:
|
21
|
+
map: 'collect'
|
22
|
+
reduce: 'inject'
|
23
|
+
find: 'detect'
|
24
|
+
find_all: 'select'
|
25
|
+
|
26
|
+
Style/Documentation:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/DoubleNegation:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/HashSyntax:
|
33
|
+
EnforcedStyle: hash_rockets
|
34
|
+
|
35
|
+
Style/SpaceInsideHashLiteralBraces:
|
36
|
+
EnforcedStyle: no_space
|
37
|
+
|
38
|
+
Style/StringLiterals:
|
39
|
+
EnforcedStyle: double_quotes
|
40
|
+
|
41
|
+
Style/TrailingComma:
|
42
|
+
EnforcedStyleForMultiline: 'comma'
|
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
before_install: gem install bundler
|
2
|
+
env:
|
3
|
+
global:
|
4
|
+
- JRUBY_OPTS="$JRUBY_OPTS --debug"
|
5
|
+
language: ruby
|
6
|
+
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
|
14
|
+
- jruby-head
|
15
|
+
- rbx-2
|
16
|
+
- ruby-head
|
17
|
+
matrix:
|
18
|
+
allow_failures:
|
19
|
+
- rvm: jruby-head
|
20
|
+
- rvm: ruby-head
|
21
|
+
fast_finish: true
|
22
|
+
sudo: false
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "rake"
|
4
|
+
|
5
|
+
group :test do
|
6
|
+
gem "coveralls"
|
7
|
+
gem "json", :platforms => [:jruby, :ruby_18, :ruby_19]
|
8
|
+
gem "mime-types", "~> 1.25", :platforms => [:jruby, :ruby_18]
|
9
|
+
gem "rack-test"
|
10
|
+
gem "rest-client", "~> 1.6.0", :platforms => [:jruby, :ruby_18]
|
11
|
+
gem "rspec", "~> 3.2"
|
12
|
+
gem "rubocop", ">= 0.30", :platforms => [:ruby_19, :ruby_20, :ruby_21, :ruby_22]
|
13
|
+
gem "simplecov", ">= 0.9"
|
14
|
+
gem "webmock"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Specify your gem's dependencies in omniauth-oauth2.gemspec
|
18
|
+
gemspec
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (C) 2014 Michael Bleigh, Erik Michaels-Ober and Intridea, Inc.
|
2
|
+
Copyright (C) 2017 Muhammad Mufid Afif and PT Harmonix Teknologi Peentar.
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# OmniAuth OAuth2
|
2
|
+
|
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]
|
7
|
+
[![Coverage Status](http://img.shields.io/coveralls/intridea/omniauth-oauth2.svg)][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).
|
18
|
+
|
19
|
+
This fork has JWT 2.0.0 compatibility with OAuth2 1.0.0 Rubygem.
|
20
|
+
|
21
|
+
## Creating an OAuth2 Strategy
|
22
|
+
|
23
|
+
To create an OmniAuth OAuth2 strategy using this gem, you can simply subclass
|
24
|
+
it and add a few extra methods like so:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'omniauth-oauth2'
|
28
|
+
|
29
|
+
module OmniAuth
|
30
|
+
module Strategies
|
31
|
+
class SomeSite < OmniAuth::Strategies::OAuth2
|
32
|
+
# Give your strategy a name.
|
33
|
+
option :name, "some_site"
|
34
|
+
|
35
|
+
# This is where you pass the options you would pass when
|
36
|
+
# initializing your consumer from the OAuth gem.
|
37
|
+
option :client_options, {:site => "https://api.somesite.com"}
|
38
|
+
|
39
|
+
# These are called after authentication has succeeded. If
|
40
|
+
# possible, you should try to set the UID without making
|
41
|
+
# additional calls (if the user id is returned with the token
|
42
|
+
# or as a URI parameter). This may not be possible with all
|
43
|
+
# providers.
|
44
|
+
uid{ raw_info['id'] }
|
45
|
+
|
46
|
+
info do
|
47
|
+
{
|
48
|
+
:name => raw_info['name'],
|
49
|
+
:email => raw_info['email']
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
extra do
|
54
|
+
{
|
55
|
+
'raw_info' => raw_info
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def raw_info
|
60
|
+
@raw_info ||= access_token.get('/me').parsed
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
That's pretty much it!
|
68
|
+
|
69
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/intridea/omniauth-oauth2/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
require "rubygems/tasks"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new
|
7
|
+
Gem::Tasks.new
|
8
|
+
|
9
|
+
task :test => :spec
|
10
|
+
|
11
|
+
begin
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
RuboCop::RakeTask.new
|
14
|
+
rescue LoadError
|
15
|
+
task :rubocop do
|
16
|
+
$stderr.puts "RuboCop is disabled"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => [:spec, :rubocop]
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require "oauth2"
|
2
|
+
require "omniauth"
|
3
|
+
require "securerandom"
|
4
|
+
require "socket" # for SocketError
|
5
|
+
require "timeout" # for Timeout::Error
|
6
|
+
|
7
|
+
module OmniAuth
|
8
|
+
module Strategies
|
9
|
+
# Authentication strategy for connecting with APIs constructed using
|
10
|
+
# the [OAuth 2.0 Specification](http://tools.ietf.org/html/draft-ietf-oauth-v2-10).
|
11
|
+
# You must generally register your application with the provider and
|
12
|
+
# utilize an application id and secret in order to authenticate using
|
13
|
+
# OAuth 2.0.
|
14
|
+
class OAuth2
|
15
|
+
include OmniAuth::Strategy
|
16
|
+
|
17
|
+
def self.inherited(subclass)
|
18
|
+
OmniAuth::Strategy.included(subclass)
|
19
|
+
end
|
20
|
+
|
21
|
+
args [:client_id, :client_secret]
|
22
|
+
|
23
|
+
option :client_id, nil
|
24
|
+
option :client_secret, nil
|
25
|
+
option :client_options, {}
|
26
|
+
option :authorize_params, {}
|
27
|
+
option :authorize_options, [:scope]
|
28
|
+
option :token_params, {}
|
29
|
+
option :token_options, []
|
30
|
+
option :auth_token_params, {}
|
31
|
+
option :provider_ignores_state, false
|
32
|
+
|
33
|
+
attr_accessor :access_token
|
34
|
+
|
35
|
+
def client
|
36
|
+
::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
|
37
|
+
end
|
38
|
+
|
39
|
+
credentials do
|
40
|
+
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?)
|
44
|
+
hash
|
45
|
+
end
|
46
|
+
|
47
|
+
def request_phase
|
48
|
+
redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
|
49
|
+
end
|
50
|
+
|
51
|
+
def authorize_params
|
52
|
+
options.authorize_params[:state] = SecureRandom.hex(24)
|
53
|
+
params = options.authorize_params.merge(options_for("authorize"))
|
54
|
+
if OmniAuth.config.test_mode
|
55
|
+
@env ||= {}
|
56
|
+
@env["rack.session"] ||= {}
|
57
|
+
end
|
58
|
+
session["omniauth.state"] = params[:state]
|
59
|
+
params
|
60
|
+
end
|
61
|
+
|
62
|
+
def token_params
|
63
|
+
options.token_params.merge(options_for("token"))
|
64
|
+
end
|
65
|
+
|
66
|
+
def callback_phase # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, PerceivedComplexity
|
67
|
+
error = request.params["error_reason"] || request.params["error"]
|
68
|
+
if error
|
69
|
+
fail!(error, CallbackError.new(request.params["error"], request.params["error_description"] || request.params["error_reason"], request.params["error_uri"]))
|
70
|
+
elsif !options.provider_ignores_state && (request.params["state"].to_s.empty? || request.params["state"] != session.delete("omniauth.state"))
|
71
|
+
fail!(:csrf_detected, CallbackError.new(:csrf_detected, "CSRF detected"))
|
72
|
+
else
|
73
|
+
self.access_token = build_access_token
|
74
|
+
self.access_token = access_token.refresh! if access_token.expired?
|
75
|
+
super
|
76
|
+
end
|
77
|
+
rescue ::OAuth2::Error, CallbackError => e
|
78
|
+
fail!(:invalid_credentials, e)
|
79
|
+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
|
80
|
+
fail!(:timeout, e)
|
81
|
+
rescue ::SocketError => e
|
82
|
+
fail!(:failed_to_connect, e)
|
83
|
+
end
|
84
|
+
|
85
|
+
protected
|
86
|
+
|
87
|
+
def build_access_token
|
88
|
+
verifier = request.params["code"]
|
89
|
+
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
|
+
end
|
91
|
+
|
92
|
+
def deep_symbolize(options)
|
93
|
+
hash = {}
|
94
|
+
options.each do |key, value|
|
95
|
+
hash[key.to_sym] = value.is_a?(Hash) ? deep_symbolize(value) : value
|
96
|
+
end
|
97
|
+
hash
|
98
|
+
end
|
99
|
+
|
100
|
+
def options_for(option)
|
101
|
+
hash = {}
|
102
|
+
options.send(:"#{option}_options").select { |key| options[key] }.each do |key|
|
103
|
+
hash[key.to_sym] = options[key]
|
104
|
+
end
|
105
|
+
hash
|
106
|
+
end
|
107
|
+
|
108
|
+
# An error that is indicated in the OAuth 2.0 callback.
|
109
|
+
# This could be a `redirect_uri_mismatch` or other
|
110
|
+
class CallbackError < StandardError
|
111
|
+
attr_accessor :error, :error_reason, :error_uri
|
112
|
+
|
113
|
+
def initialize(error, error_reason = nil, error_uri = nil)
|
114
|
+
self.error = error
|
115
|
+
self.error_reason = error_reason
|
116
|
+
self.error_uri = error_uri
|
117
|
+
end
|
118
|
+
|
119
|
+
def message
|
120
|
+
[error, error_reason, error_uri].compact.join(" | ")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
OmniAuth.config.add_camelization "oauth2", "OAuth2"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "omniauth-oauth2/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.add_dependency "oauth2", "~> 1.4"
|
7
|
+
gem.add_dependency "omniauth", "~> 1.2"
|
8
|
+
|
9
|
+
gem.add_development_dependency "bundler", "~> 1.0"
|
10
|
+
gem.add_development_dependency "rubygems-tasks"
|
11
|
+
|
12
|
+
gem.authors = ["Michael Bleigh", "Erik Michaels-Ober", "Muhammad Mufid Afif"]
|
13
|
+
gem.email = ["michael@intridea.com", "sferik@gmail.com", "mufid@peentar.com"]
|
14
|
+
gem.description = "An abstract OAuth2 strategy for OmniAuth."
|
15
|
+
gem.summary = gem.description
|
16
|
+
gem.homepage = "https://github.com/peentar/omniauth-oauth2"
|
17
|
+
gem.licenses = %w(MIT)
|
18
|
+
|
19
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) }
|
20
|
+
gem.files = `git ls-files`.split("\n")
|
21
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
gem.name = "peentar-omniauth-oauth2"
|
23
|
+
gem.require_paths = %w(lib)
|
24
|
+
gem.version = OmniAuth::OAuth2::VERSION
|
25
|
+
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
|
+
if RUBY_VERSION >= "1.9"
|
5
|
+
require "simplecov"
|
6
|
+
require "coveralls"
|
7
|
+
|
8
|
+
SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
|
9
|
+
|
10
|
+
SimpleCov.start do
|
11
|
+
minimum_coverage(78.48)
|
12
|
+
end
|
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
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::OAuth2 do
|
4
|
+
def app
|
5
|
+
lambda do |_env|
|
6
|
+
[200, {}, ["Hello."]]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
let(:fresh_strategy) { Class.new(OmniAuth::Strategies::OAuth2) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
OmniAuth.config.test_mode = true
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
OmniAuth.config.test_mode = false
|
17
|
+
end
|
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
|
+
|
28
|
+
describe "#client" do
|
29
|
+
subject { fresh_strategy }
|
30
|
+
|
31
|
+
it "is initialized with symbolized client_options" do
|
32
|
+
instance = subject.new(app, :client_options => {"authorize_url" => "https://example.com"})
|
33
|
+
expect(instance.client.options[:authorize_url]).to eq("https://example.com")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "sets ssl options as connection options" do
|
37
|
+
instance = subject.new(app, :client_options => {"ssl" => {"ca_path" => "foo"}})
|
38
|
+
expect(instance.client.options[:connection_opts][:ssl]).to eq(:ca_path => "foo")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#authorize_params" do
|
43
|
+
subject { fresh_strategy }
|
44
|
+
|
45
|
+
it "includes any authorize params passed in the :authorize_params option" do
|
46
|
+
instance = subject.new("abc", "def", :authorize_params => {:foo => "bar", :baz => "zip"})
|
47
|
+
expect(instance.authorize_params["foo"]).to eq("bar")
|
48
|
+
expect(instance.authorize_params["baz"]).to eq("zip")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "includes top-level options that are marked as :authorize_options" do
|
52
|
+
instance = subject.new("abc", "def", :authorize_options => [:scope, :foo, :state], :scope => "bar", :foo => "baz")
|
53
|
+
expect(instance.authorize_params["scope"]).to eq("bar")
|
54
|
+
expect(instance.authorize_params["foo"]).to eq("baz")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "includes random state in the authorize params" do
|
58
|
+
instance = subject.new("abc", "def")
|
59
|
+
expect(instance.authorize_params.keys).to eq(["state"])
|
60
|
+
expect(instance.session["omniauth.state"]).not_to be_empty
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#token_params" do
|
65
|
+
subject { fresh_strategy }
|
66
|
+
|
67
|
+
it "includes any authorize params passed in the :authorize_params option" do
|
68
|
+
instance = subject.new("abc", "def", :token_params => {:foo => "bar", :baz => "zip"})
|
69
|
+
expect(instance.token_params).to eq("foo" => "bar", "baz" => "zip")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "includes top-level options that are marked as :authorize_options" do
|
73
|
+
instance = subject.new("abc", "def", :token_options => [:scope, :foo], :scope => "bar", :foo => "baz")
|
74
|
+
expect(instance.token_params).to eq("scope" => "bar", "foo" => "baz")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#callback_phase" do
|
79
|
+
subject { fresh_strategy }
|
80
|
+
it "calls fail with the client error received" do
|
81
|
+
instance = subject.new("abc", "def")
|
82
|
+
allow(instance).to receive(:request) do
|
83
|
+
double("Request", :params => {"error_reason" => "user_denied", "error" => "access_denied"})
|
84
|
+
end
|
85
|
+
|
86
|
+
expect(instance).to receive(:fail!).with("user_denied", anything)
|
87
|
+
instance.callback_phase
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe OmniAuth::Strategies::OAuth2::CallbackError do
|
93
|
+
let(:error) { Class.new(OmniAuth::Strategies::OAuth2::CallbackError) }
|
94
|
+
describe "#message" do
|
95
|
+
subject { error }
|
96
|
+
it "includes all of the attributes" do
|
97
|
+
instance = subject.new("error", "description", "uri")
|
98
|
+
expect(instance.message).to match(/error/)
|
99
|
+
expect(instance.message).to match(/description/)
|
100
|
+
expect(instance.message).to match(/uri/)
|
101
|
+
end
|
102
|
+
it "includes all of the attributes" do
|
103
|
+
instance = subject.new(nil, :symbol)
|
104
|
+
expect(instance.message).to eq("symbol")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: peentar-omniauth-oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Bleigh
|
8
|
+
- Erik Michaels-Ober
|
9
|
+
- Muhammad Mufid Afif
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2017-10-02 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: oauth2
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.4'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.4'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: omniauth
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.2'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.2'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: bundler
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rubygems-tasks
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
description: An abstract OAuth2 strategy for OmniAuth.
|
72
|
+
email:
|
73
|
+
- michael@intridea.com
|
74
|
+
- sferik@gmail.com
|
75
|
+
- mufid@peentar.com
|
76
|
+
executables: []
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- ".gitignore"
|
81
|
+
- ".rspec"
|
82
|
+
- ".rubocop.yml"
|
83
|
+
- ".travis.yml"
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE.md
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- lib/omniauth-oauth2.rb
|
89
|
+
- lib/omniauth-oauth2/version.rb
|
90
|
+
- lib/omniauth/strategies/oauth2.rb
|
91
|
+
- omniauth-oauth2.gemspec
|
92
|
+
- spec/helper.rb
|
93
|
+
- spec/omniauth/strategies/oauth2_spec.rb
|
94
|
+
homepage: https://github.com/peentar/omniauth-oauth2
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.6.13
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: An abstract OAuth2 strategy for OmniAuth.
|
118
|
+
test_files: []
|