omniauth-oauth 1.2.0 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1dfca9af1de8c628340193490f5c0e33a3075ce7baab4b72b6e4d07709204b71
4
- data.tar.gz: 9294cf2611fee8dea9cfd28765c904b2150c6b271f9ae1840eff9e03cc1d97d5
3
+ metadata.gz: d19f0af5048d2c89c4b17b6915b01eddf206cb77834d461a70658ae2cc3e1c23
4
+ data.tar.gz: 3c77259ad9b59479471520fb39b1883d3697bc3a8648152ccbdbc2225068442d
5
5
  SHA512:
6
- metadata.gz: a5b01f08e32d842622a5711071f9925e13f891c70b7f0ca96e0dcdca3957858a2555c821669c809fc29628c95213bd9dca0204374d9e4ab193a7b650dc0a5552
7
- data.tar.gz: 0a4de26cf1b884da55b1567ca2cfb42b90db8e0fc32e45fe39cc1b588b980f5ebee344bfc8cee54cc128e0f6b99127601708294357975de5ca5d8c2a2e0e8580
6
+ metadata.gz: d4b7f5e559a173a6cde49cbb212ffb8721f07f4f90879009c79c8f46fa55754dc820ce39b5f8a9536361fcf08dfd55a3c588956ed0dc06bef352b3d027a9f2de
7
+ data.tar.gz: aa7df709b7133881888a1363688aaa6f31752257cf9c1533f67fdcc1622938dbdf0e764d215ffe80412b59e1b20b5f9b04fae82f4126c1480a40f98207e6de13
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2014 Michael Bleigh, Erik Michaels-Ober and Intridea, Inc.
1
+ Copyright (c) 2011-2026 Michael Bleigh, Erik Berlin and Intridea, Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # OmniAuth OAuth
2
2
 
3
+ [![Gem Version](http://img.shields.io/gem/v/omniauth-oauth.svg)][gem]
4
+ [![Ruby](https://github.com/omniauth/omniauth-oauth/actions/workflows/ci.yml/badge.svg)][githubactions]
5
+ [![Maintainability](https://qlty.sh/gh/omniauth/projects/omniauth-oauth/maintainability.svg)][qlty]
6
+
7
+ [gem]: https://rubygems.org/gems/omniauth-oauth
8
+ [githubactions]: https://github.com/omniauth/omniauth-oauth/actions/workflows/ci.yml
9
+ [qlty]: https://qlty.sh/gh/omniauth/projects/omniauth-oauth
10
+
3
11
  This gem contains a generic OAuth strategy for OmniAuth. It is meant to
4
12
  serve as a building block strategy for other strategies and not to be
5
13
  used independently (since it has no inherent way to gather uid and user
@@ -45,7 +53,7 @@ module OmniAuth
45
53
  end
46
54
 
47
55
  def raw_info
48
- @raw_info ||= JSON.load(access_token.get('/me.json')).body
56
+ @raw_info ||= JSON.load(access_token.get('/me.json').body)
49
57
  end
50
58
  end
51
59
  end
@@ -6,7 +6,7 @@ module OmniAuth
6
6
  class OAuth
7
7
  include OmniAuth::Strategy
8
8
 
9
- args [:consumer_key, :consumer_secret]
9
+ args %i[consumer_key consumer_secret]
10
10
  option :consumer_key, nil
11
11
  option :consumer_secret, nil
12
12
  option :client_options, {}
@@ -19,41 +19,35 @@ module OmniAuth
19
19
 
20
20
  def consumer
21
21
  consumer = ::OAuth::Consumer.new(options.consumer_key, options.consumer_secret, options.client_options)
22
- consumer.http.open_timeout = options.open_timeout if options.open_timeout
23
- consumer.http.read_timeout = options.read_timeout if options.read_timeout
22
+ open_timeout = options.open_timeout
23
+ read_timeout = options.read_timeout
24
+ consumer.http.open_timeout = open_timeout if open_timeout
25
+ consumer.http.read_timeout = read_timeout if read_timeout
24
26
  consumer
25
27
  end
26
28
 
27
- def request_phase # rubocop:disable MethodLength
29
+ def request_phase
28
30
  request_token = consumer.get_request_token({:oauth_callback => callback_url}, options.request_params)
29
31
  session["oauth"] ||= {}
30
- session["oauth"][name.to_s] = {"callback_confirmed" => request_token.callback_confirmed?, "request_token" => request_token.token, "request_secret" => request_token.secret}
32
+ session.fetch("oauth")[name.to_s] = {"callback_confirmed" => request_token.callback_confirmed?, "request_token" => request_token.token, "request_secret" => request_token.secret}
31
33
 
32
34
  if request_token.callback_confirmed?
33
- redirect request_token.authorize_url(options[:authorize_params])
35
+ redirect request_token.authorize_url(options.authorize_params)
34
36
  else
35
- redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url))
37
+ redirect request_token.authorize_url(options.authorize_params.merge(:oauth_callback => callback_url))
36
38
  end
37
-
38
39
  rescue ::Timeout::Error => e
39
40
  fail!(:timeout, e)
40
41
  rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
41
42
  fail!(:service_unavailable, e)
42
43
  end
43
44
 
44
- def callback_phase # rubocop:disable MethodLength
45
- fail(OmniAuth::NoSessionError, "Session Expired") if session["oauth"].nil?
46
-
47
- request_token = ::OAuth::RequestToken.new(consumer, session["oauth"][name.to_s].delete("request_token"), session["oauth"][name.to_s].delete("request_secret"))
48
-
49
- opts = {}
50
- if session["oauth"][name.to_s]["callback_confirmed"]
51
- opts[:oauth_verifier] = request["oauth_verifier"]
52
- else
53
- opts[:oauth_callback] = callback_url
54
- end
45
+ def callback_phase
46
+ provider_session = (session["oauth"] || {})[name.to_s]
47
+ raise(NoSessionError, "Session Expired") unless provider_session
55
48
 
56
- @access_token = request_token.get_access_token(opts)
49
+ request_token = ::OAuth::RequestToken.new(consumer, provider_session.delete("request_token"), provider_session.delete("request_secret"))
50
+ @access_token = request_token.get_access_token(access_token_options(provider_session))
57
51
  super
58
52
  rescue ::Timeout::Error => e
59
53
  fail!(:timeout, e)
@@ -65,6 +59,16 @@ module OmniAuth
65
59
  fail!(:session_expired, e)
66
60
  end
67
61
 
62
+ # The verifier when the provider confirmed the callback URL (OAuth
63
+ # 1.0a), or the callback URL when it didn't (OAuth 1.0).
64
+ def access_token_options(provider_session)
65
+ if provider_session["callback_confirmed"]
66
+ {:oauth_verifier => request.params["oauth_verifier"]}
67
+ else
68
+ {:oauth_callback => callback_url}
69
+ end
70
+ end
71
+
68
72
  credentials do
69
73
  {"token" => access_token.token, "secret" => access_token.secret}
70
74
  end
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module OAuth
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,58 @@
1
+ module OmniAuth
2
+ module OAuth
3
+ VERSION: String
4
+ end
5
+
6
+ module Strategies
7
+ # A generic OAuth 1.0a strategy. Provider strategies subclass it and set
8
+ # client_options (site, request_token_path, authorize_path, and
9
+ # access_token_path) for their provider.
10
+ class OAuth
11
+ include Strategy
12
+ extend Strategy::ClassMethods
13
+
14
+ # The options this strategy adds to OmniAuth's. Strategy::Options
15
+ # answers them through Hashie::Mash's method_missing.
16
+ interface _Options
17
+ def consumer_key: () -> String?
18
+ def consumer_secret: () -> String?
19
+ def client_options: () -> Strategy::Options
20
+ def open_timeout: () -> (Integer | Float | nil)
21
+ def read_timeout: () -> (Integer | Float | nil)
22
+ def authorize_params: () -> Strategy::Options
23
+ def request_params: () -> Strategy::Options
24
+ end
25
+
26
+ # The fetcher blocks run with the strategy instance as self.
27
+ def self.uid: () { () [self: instance] -> untyped } -> Proc
28
+ | () -> Proc?
29
+
30
+ def self.info: () { () [self: instance] -> Hash[untyped, untyped]? } -> Proc
31
+ | () -> Proc?
32
+
33
+ def self.extra: () { () [self: instance] -> Hash[untyped, untyped]? } -> Proc
34
+ | () -> Proc?
35
+
36
+ def self.credentials: () { () [self: instance] -> Hash[untyped, untyped]? } -> Proc
37
+ | () -> Proc?
38
+
39
+ def options: () -> (Strategy::Options & _Options)
40
+
41
+ # Set by the callback phase, which runs before the fetcher blocks that
42
+ # read it.
43
+ attr_reader access_token: ::OAuth::AccessToken
44
+
45
+ @access_token: ::OAuth::AccessToken
46
+
47
+ def consumer: () -> ::OAuth::Consumer
48
+
49
+ def request_phase: () -> rack_response
50
+
51
+ def callback_phase: () -> rack_response
52
+
53
+ # The verifier when the provider confirmed the callback URL (OAuth
54
+ # 1.0a), or the callback URL when it didn't (OAuth 1.0).
55
+ def access_token_options: (Hash[String, untyped] provider_session) -> ({ oauth_verifier: String? } | { oauth_callback: String })
56
+ end
57
+ end
58
+ end
metadata CHANGED
@@ -1,36 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
+ - Erik Berlin
7
8
  - Michael Bleigh
8
- - Erik Michaels-Ober
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2021-01-28 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: omniauth
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
- - - ">="
17
+ - - "~>"
19
18
  - !ruby/object:Gem::Version
20
- version: '1.0'
21
- - - "<"
19
+ version: '2.3'
20
+ - - ">="
22
21
  - !ruby/object:Gem::Version
23
- version: '3'
22
+ version: 2.3.1
24
23
  type: :runtime
25
24
  prerelease: false
26
25
  version_requirements: !ruby/object:Gem::Requirement
27
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.3'
28
30
  - - ">="
29
31
  - !ruby/object:Gem::Version
30
- version: '1.0'
31
- - - "<"
32
+ version: 2.3.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: cgi
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: '3'
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
34
47
  - !ruby/object:Gem::Dependency
35
48
  name: oauth
36
49
  requirement: !ruby/object:Gem::Requirement
@@ -45,33 +58,46 @@ dependencies:
45
58
  - - ">="
46
59
  - !ruby/object:Gem::Version
47
60
  version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rack
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 1.6.2
68
+ - - "<"
69
+ - !ruby/object:Gem::Version
70
+ version: '4'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 1.6.2
78
+ - - "<"
79
+ - !ruby/object:Gem::Version
80
+ version: '4'
48
81
  description: A generic OAuth (1.0/1.0a) strategy for OmniAuth.
49
82
  email:
50
- - michael@intridea.com
51
83
  - sferik@gmail.com
84
+ - michael@intridea.com
52
85
  executables: []
53
86
  extensions: []
54
87
  extra_rdoc_files: []
55
88
  files:
56
- - ".gitignore"
57
- - ".rspec"
58
- - ".rubocop.yml"
59
- - ".travis.yml"
60
- - Gemfile
61
89
  - LICENSE.md
62
90
  - README.md
63
- - Rakefile
64
91
  - lib/omniauth-oauth.rb
65
92
  - lib/omniauth-oauth/version.rb
66
93
  - lib/omniauth/strategies/oauth.rb
67
- - omniauth-oauth.gemspec
68
- - spec/helper.rb
69
- - spec/omniauth/strategies/oauth_spec.rb
70
- homepage: https://github.com/intridea/omniauth-oauth
94
+ - sig/omniauth-oauth.rbs
95
+ homepage: https://github.com/omniauth/omniauth-oauth
71
96
  licenses:
72
97
  - MIT
73
- metadata: {}
74
- post_install_message:
98
+ metadata:
99
+ changelog_uri: https://github.com/omniauth/omniauth-oauth/blob/master/CHANGELOG.md
100
+ rubygems_mfa_required: 'true'
75
101
  rdoc_options: []
76
102
  require_paths:
77
103
  - lib
@@ -79,17 +105,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
105
  requirements:
80
106
  - - ">="
81
107
  - !ruby/object:Gem::Version
82
- version: '0'
108
+ version: '2.5'
83
109
  required_rubygems_version: !ruby/object:Gem::Requirement
84
110
  requirements:
85
111
  - - ">="
86
112
  - !ruby/object:Gem::Version
87
113
  version: '0'
88
114
  requirements: []
89
- rubygems_version: 3.0.3
90
- signing_key:
115
+ rubygems_version: 4.0.20
91
116
  specification_version: 4
92
117
  summary: A generic OAuth (1.0/1.0a) strategy for OmniAuth.
93
- test_files:
94
- - spec/helper.rb
95
- - spec/omniauth/strategies/oauth_spec.rb
118
+ test_files: []
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format=progress
data/.rubocop.yml DELETED
@@ -1,55 +0,0 @@
1
- Metrics/AbcSize:
2
- Enabled: false
3
-
4
- Metrics/BlockNesting:
5
- Max: 2
6
-
7
- Metrics/LineLength:
8
- AllowURI: true
9
- Enabled: false
10
-
11
- Metrics/MethodLength:
12
- CountComments: false
13
- Max: 10
14
-
15
- Metrics/ParameterLists:
16
- Max: 4
17
- CountKeywordArgs: true
18
-
19
- Style/AccessModifierIndentation:
20
- EnforcedStyle: outdent
21
-
22
- Style/CollectionMethods:
23
- PreferredMethods:
24
- map: 'collect'
25
- reduce: 'inject'
26
- find: 'detect'
27
- find_all: 'select'
28
-
29
- Style/Documentation:
30
- Enabled: false
31
-
32
- Style/DotPosition:
33
- EnforcedStyle: trailing
34
-
35
- Style/DoubleNegation:
36
- Enabled: false
37
-
38
- Style/FileName:
39
- Exclude:
40
- - 'lib/omniauth-oauth.rb'
41
-
42
- Style/HashSyntax:
43
- EnforcedStyle: hash_rockets
44
-
45
- Style/Lambda:
46
- Enabled: false
47
-
48
- Style/SpaceInsideHashLiteralBraces:
49
- EnforcedStyle: no_space
50
-
51
- Style/StringLiterals:
52
- EnforcedStyle: double_quotes
53
-
54
- Style/TrailingComma:
55
- EnforcedStyleForMultiline: 'comma'
data/.travis.yml DELETED
@@ -1,24 +0,0 @@
1
- before_install: gem install bundler
2
- env:
3
- global:
4
- - JRUBY_OPTS="$JRUBY_OPTS --debug"
5
- language: ruby
6
- rvm:
7
- - 2.3
8
- - 2.4
9
- - 2.5
10
- - 2.6
11
- - 2.7
12
- - 3.0
13
- - jruby-18mode
14
- - jruby-19mode
15
- - jruby-head
16
- - rbx-2
17
- - ruby-head
18
- matrix:
19
- allow_failures:
20
- - rvm: jruby-head
21
- - rvm: ruby-head
22
- - rvm: rbx-2 # TODO: Fix
23
- fast_finish: true
24
- sudo: false
data/Gemfile DELETED
@@ -1,13 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem "rake"
6
-
7
- group :test do
8
- gem "rack-test"
9
- gem "rspec", "~> 3.2"
10
- gem "rubocop", ">= 0.30", :platforms => [:ruby_19, :ruby_20, :ruby_21, :ruby_22]
11
- gem "simplecov"
12
- gem "webmock"
13
- end
data/Rakefile DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
3
- require "rspec/core/rake_task"
4
-
5
- RSpec::Core::RakeTask.new
6
-
7
- begin
8
- require "rubocop/rake_task"
9
- RuboCop::RakeTask.new
10
- rescue LoadError
11
- task :rubocop do
12
- $stderr.puts "Rubocop is disabled"
13
- end
14
- end
15
-
16
- task :default => [:spec, :rubocop]
@@ -1,20 +0,0 @@
1
- require File.expand_path("../lib/omniauth-oauth/version", __FILE__)
2
-
3
- Gem::Specification.new do |gem|
4
- gem.authors = ["Michael Bleigh", "Erik Michaels-Ober"]
5
- gem.email = ["michael@intridea.com", "sferik@gmail.com"]
6
- gem.description = "A generic OAuth (1.0/1.0a) strategy for OmniAuth."
7
- gem.summary = gem.description
8
- gem.homepage = "https://github.com/intridea/omniauth-oauth"
9
- gem.license = "MIT"
10
-
11
- gem.add_dependency "omniauth", ">= 1.0", "< 3"
12
- gem.add_dependency "oauth"
13
-
14
- gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
15
- gem.files = `git ls-files`.split("\n")
16
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- gem.name = "omniauth-oauth"
18
- gem.require_paths = ["lib"]
19
- gem.version = OmniAuth::OAuth::VERSION
20
- end
data/spec/helper.rb DELETED
@@ -1,21 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path("..", __FILE__)
2
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
- require "simplecov"
4
- SimpleCov.start do
5
- minimum_coverage(89.79)
6
- end
7
- require "rspec"
8
- require "rack/test"
9
- require "webmock/rspec"
10
- require "omniauth"
11
- require "omniauth-oauth"
12
-
13
- OmniAuth.config.request_validation_phase = nil
14
-
15
- RSpec.configure do |config|
16
- config.include WebMock::API
17
- config.include Rack::Test::Methods
18
- config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
19
- end
20
-
21
- OmniAuth.config.logger = Logger.new("/dev/null")
@@ -1,147 +0,0 @@
1
- require "helper"
2
-
3
- describe "OmniAuth::Strategies::OAuth" do
4
- class MyOAuthProvider < OmniAuth::Strategies::OAuth
5
- uid { access_token.token }
6
- info { {"name" => access_token.token} }
7
- end
8
-
9
- def app
10
- Rack::Builder.new do
11
- use OmniAuth::Test::PhonySession
12
- use OmniAuth::Builder do
13
- provider MyOAuthProvider, "abc", "def", :client_options => {:site => "https://api.example.org"}, :name => "example.org"
14
- provider MyOAuthProvider, "abc", "def", :client_options => {:site => "https://api.example.org"}, :authorize_params => {:abc => "def"}, :name => "example.org_with_authorize_params"
15
- provider MyOAuthProvider, "abc", "def", :client_options => {:site => "https://api.example.org"}, :request_params => {:scope => "http://foobar.example.org"}, :name => "example.org_with_request_params"
16
- end
17
- run lambda { |env| [404, {"Content-Type" => "text/plain"}, [env.key?("omniauth.auth").to_s]] }
18
- end.to_app
19
- end
20
-
21
- def session
22
- last_request.env["rack.session"]
23
- end
24
-
25
- before do
26
- stub_request(:post, "https://api.example.org/oauth/request_token").
27
- to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret&oauth_callback_confirmed=true")
28
- end
29
-
30
- it "should add a camelization for itself" do
31
- expect(OmniAuth::Utils.camelize("oauth")).to eq("OAuth")
32
- end
33
-
34
- describe "/auth/{name}" do
35
- context "successful" do
36
- before do
37
- post "/auth/example.org"
38
- end
39
-
40
- it "should redirect to authorize_url" do
41
- expect(last_response).to be_redirect
42
- expect(last_response.headers["Location"]).to eq("https://api.example.org/oauth/authorize?oauth_token=yourtoken")
43
- end
44
-
45
- it "should redirect to authorize_url with authorize_params when set" do
46
- post "/auth/example.org_with_authorize_params"
47
- expect(last_response).to be_redirect
48
- expect([
49
- "https://api.example.org/oauth/authorize?abc=def&oauth_token=yourtoken",
50
- "https://api.example.org/oauth/authorize?oauth_token=yourtoken&abc=def",
51
- ]).to be_include(last_response.headers["Location"])
52
- end
53
-
54
- it "should set appropriate session variables" do
55
- expect(session["oauth"]).to eq("example.org" => {"callback_confirmed" => true, "request_token" => "yourtoken", "request_secret" => "yoursecret"})
56
- end
57
-
58
- it "should pass request_params to get_request_token" do
59
- post "/auth/example.org_with_request_params"
60
- expect(WebMock).to have_requested(:post, "https://api.example.org/oauth/request_token").
61
- with { |req| req.body == "scope=http%3A%2F%2Ffoobar.example.org" }
62
- end
63
- end
64
-
65
- context "unsuccessful" do
66
- before do
67
- stub_request(:post, "https://api.example.org/oauth/request_token").
68
- to_raise(::Net::HTTPFatalError.new('502 "Bad Gateway"', nil))
69
- post "/auth/example.org"
70
- end
71
-
72
- it "should call fail! with :service_unavailable" do
73
- expect(last_request.env["omniauth.error"]).to be_kind_of(::Net::HTTPFatalError)
74
- last_request.env["omniauth.error.type"] = :service_unavailable
75
- end
76
-
77
- context "SSL failure" do
78
- before do
79
- stub_request(:post, "https://api.example.org/oauth/request_token").
80
- to_raise(::OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed"))
81
- post "/auth/example.org"
82
- end
83
-
84
- it "should call fail! with :service_unavailable" do
85
- expect(last_request.env["omniauth.error"]).to be_kind_of(::OpenSSL::SSL::SSLError)
86
- last_request.env["omniauth.error.type"] = :service_unavailable
87
- end
88
- end
89
- end
90
- end
91
-
92
- describe "/auth/{name}/callback" do
93
- before do
94
- stub_request(:post, "https://api.example.org/oauth/access_token").
95
- to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
96
- get "/auth/example.org/callback", {:oauth_verifier => "dudeman"}, "rack.session" => {"oauth" => {"example.org" => {"callback_confirmed" => true, "request_token" => "yourtoken", "request_secret" => "yoursecret"}}}
97
- end
98
-
99
- it "should exchange the request token for an access token" do
100
- expect(last_request.env["omniauth.auth"]["provider"]).to eq("example.org")
101
- expect(last_request.env["omniauth.auth"]["extra"]["access_token"]).to be_kind_of(OAuth::AccessToken)
102
- end
103
-
104
- it "should call through to the master app" do
105
- expect(last_response.body).to eq("true")
106
- end
107
-
108
- context "bad gateway (or any 5xx) for access_token" do
109
- before do
110
- stub_request(:post, "https://api.example.org/oauth/access_token") .
111
- to_raise(::Net::HTTPFatalError.new('502 "Bad Gateway"', nil))
112
- get "/auth/example.org/callback", {:oauth_verifier => "dudeman"}, "rack.session" => {"oauth" => {"example.org" => {"callback_confirmed" => true, "request_token" => "yourtoken", "request_secret" => "yoursecret"}}}
113
- end
114
-
115
- it "should call fail! with :service_unavailable" do
116
- expect(last_request.env["omniauth.error"]).to be_kind_of(::Net::HTTPFatalError)
117
- last_request.env["omniauth.error.type"] = :service_unavailable
118
- end
119
- end
120
-
121
- context "SSL failure" do
122
- before do
123
- stub_request(:post, "https://api.example.org/oauth/access_token") .
124
- to_raise(::OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed"))
125
- get "/auth/example.org/callback", {:oauth_verifier => "dudeman"}, "rack.session" => {"oauth" => {"example.org" => {"callback_confirmed" => true, "request_token" => "yourtoken", "request_secret" => "yoursecret"}}}
126
- end
127
-
128
- it "should call fail! with :service_unavailable" do
129
- expect(last_request.env["omniauth.error"]).to be_kind_of(::OpenSSL::SSL::SSLError)
130
- last_request.env["omniauth.error.type"] = :service_unavailable
131
- end
132
- end
133
- end
134
-
135
- describe "/auth/{name}/callback with expired session" do
136
- before do
137
- stub_request(:post, "https://api.example.org/oauth/access_token").
138
- to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
139
- get "/auth/example.org/callback", {:oauth_verifier => "dudeman"}, "rack.session" => {}
140
- end
141
-
142
- it "should call fail! with :session_expired" do
143
- expect(last_request.env["omniauth.error"]).to be_kind_of(::OmniAuth::NoSessionError)
144
- last_request.env["omniauth.error.type"] = :session_expired
145
- end
146
- end
147
- end