omniauth-oauth 1.2.1 → 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 +4 -4
- data/LICENSE.md +1 -1
- data/README.md +9 -1
- data/lib/omniauth/strategies/oauth.rb +24 -20
- data/lib/omniauth-oauth/version.rb +1 -1
- data/sig/omniauth-oauth.rbs +58 -0
- metadata +33 -30
- data/.gitignore +0 -17
- data/.rspec +0 -2
- data/.rubocop.yml +0 -55
- data/.travis.yml +0 -24
- data/Gemfile +0 -13
- data/Rakefile +0 -16
- data/omniauth-oauth.gemspec +0 -21
- data/spec/helper.rb +0 -21
- data/spec/omniauth/strategies/oauth_spec.rb +0 -186
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d19f0af5048d2c89c4b17b6915b01eddf206cb77834d461a70658ae2cc3e1c23
|
|
4
|
+
data.tar.gz: 3c77259ad9b59479471520fb39b1883d3697bc3a8648152ccbdbc2225068442d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4b7f5e559a173a6cde49cbb212ffb8721f07f4f90879009c79c8f46fa55754dc820ce39b5f8a9536361fcf08dfd55a3c588956ed0dc06bef352b3d027a9f2de
|
|
7
|
+
data.tar.gz: aa7df709b7133881888a1363688aaa6f31752257cf9c1533f67fdcc1622938dbdf0e764d215ffe80412b59e1b20b5f9b04fae82f4126c1480a40f98207e6de13
|
data/LICENSE.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (
|
|
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]
|
|
4
|
+
[][githubactions]
|
|
5
|
+
[][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')
|
|
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 [
|
|
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
|
-
|
|
23
|
-
|
|
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
|
|
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
|
|
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
|
|
35
|
+
redirect request_token.authorize_url(options.authorize_params)
|
|
34
36
|
else
|
|
35
|
-
redirect request_token.authorize_url(options
|
|
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
|
|
45
|
-
|
|
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.respond_to?(:params) ? request.params["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
|
-
|
|
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
|
|
@@ -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.
|
|
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:
|
|
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: '
|
|
21
|
-
- - "
|
|
19
|
+
version: '2.3'
|
|
20
|
+
- - ">="
|
|
22
21
|
- !ruby/object:Gem::Version
|
|
23
|
-
version:
|
|
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:
|
|
31
|
-
|
|
32
|
+
version: 2.3.1
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: cgi
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
32
45
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
46
|
+
version: '0'
|
|
34
47
|
- !ruby/object:Gem::Dependency
|
|
35
48
|
name: oauth
|
|
36
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -67,31 +80,24 @@ dependencies:
|
|
|
67
80
|
version: '4'
|
|
68
81
|
description: A generic OAuth (1.0/1.0a) strategy for OmniAuth.
|
|
69
82
|
email:
|
|
70
|
-
- michael@intridea.com
|
|
71
83
|
- sferik@gmail.com
|
|
84
|
+
- michael@intridea.com
|
|
72
85
|
executables: []
|
|
73
86
|
extensions: []
|
|
74
87
|
extra_rdoc_files: []
|
|
75
88
|
files:
|
|
76
|
-
- ".gitignore"
|
|
77
|
-
- ".rspec"
|
|
78
|
-
- ".rubocop.yml"
|
|
79
|
-
- ".travis.yml"
|
|
80
|
-
- Gemfile
|
|
81
89
|
- LICENSE.md
|
|
82
90
|
- README.md
|
|
83
|
-
- Rakefile
|
|
84
91
|
- lib/omniauth-oauth.rb
|
|
85
92
|
- lib/omniauth-oauth/version.rb
|
|
86
93
|
- lib/omniauth/strategies/oauth.rb
|
|
87
|
-
- omniauth-oauth.
|
|
88
|
-
|
|
89
|
-
- spec/omniauth/strategies/oauth_spec.rb
|
|
90
|
-
homepage: https://github.com/intridea/omniauth-oauth
|
|
94
|
+
- sig/omniauth-oauth.rbs
|
|
95
|
+
homepage: https://github.com/omniauth/omniauth-oauth
|
|
91
96
|
licenses:
|
|
92
97
|
- MIT
|
|
93
|
-
metadata:
|
|
94
|
-
|
|
98
|
+
metadata:
|
|
99
|
+
changelog_uri: https://github.com/omniauth/omniauth-oauth/blob/master/CHANGELOG.md
|
|
100
|
+
rubygems_mfa_required: 'true'
|
|
95
101
|
rdoc_options: []
|
|
96
102
|
require_paths:
|
|
97
103
|
- lib
|
|
@@ -99,17 +105,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
99
105
|
requirements:
|
|
100
106
|
- - ">="
|
|
101
107
|
- !ruby/object:Gem::Version
|
|
102
|
-
version: '
|
|
108
|
+
version: '2.5'
|
|
103
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
110
|
requirements:
|
|
105
111
|
- - ">="
|
|
106
112
|
- !ruby/object:Gem::Version
|
|
107
113
|
version: '0'
|
|
108
114
|
requirements: []
|
|
109
|
-
rubygems_version:
|
|
110
|
-
signing_key:
|
|
115
|
+
rubygems_version: 4.0.20
|
|
111
116
|
specification_version: 4
|
|
112
117
|
summary: A generic OAuth (1.0/1.0a) strategy for OmniAuth.
|
|
113
|
-
test_files:
|
|
114
|
-
- spec/helper.rb
|
|
115
|
-
- spec/omniauth/strategies/oauth_spec.rb
|
|
118
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
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
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]
|
data/omniauth-oauth.gemspec
DELETED
|
@@ -1,21 +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
|
-
gem.add_dependency "rack", ">= 1.6.2", "< 4"
|
|
14
|
-
|
|
15
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
16
|
-
gem.files = `git ls-files`.split("\n")
|
|
17
|
-
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
18
|
-
gem.name = "omniauth-oauth"
|
|
19
|
-
gem.require_paths = ["lib"]
|
|
20
|
-
gem.version = OmniAuth::OAuth::VERSION
|
|
21
|
-
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,186 +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 Rack 2.x and 3.x" 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
|
-
end
|
|
140
|
-
|
|
141
|
-
context "Rack 2.x style request" do
|
|
142
|
-
before do
|
|
143
|
-
get "/auth/example.org/callback", {"oauth_verifier" => "dudeman"}, "rack.session" => {"oauth" => {"example.org" => {"callback_confirmed" => true, "request_token" => "yourtoken", "request_secret" => "yoursecret"}}}
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
it "should exchange the request token for an access token" do
|
|
147
|
-
expect(last_request.env["omniauth.auth"]["provider"]).to eq("example.org")
|
|
148
|
-
expect(last_request.env["omniauth.auth"]["extra"]["access_token"]).to be_kind_of(OAuth::AccessToken)
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
it "should call through to the master app" do
|
|
152
|
-
expect(last_response.body).to eq("true")
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
context "Rack 3.x style request" do
|
|
157
|
-
before do
|
|
158
|
-
# Simulate Rack 3.x behavior by putting oauth_verifier in the params
|
|
159
|
-
allow_any_instance_of(Rack::Request).to receive(:params).and_return({"oauth_verifier" => "dudeman"})
|
|
160
|
-
get "/auth/example.org/callback", {}, "rack.session" => {"oauth" => {"example.org" => {"callback_confirmed" => true, "request_token" => "yourtoken", "request_secret" => "yoursecret"}}}
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
it "should exchange the request token for an access token" do
|
|
164
|
-
expect(last_request.env["omniauth.auth"]["provider"]).to eq("example.org")
|
|
165
|
-
expect(last_request.env["omniauth.auth"]["extra"]["access_token"]).to be_kind_of(OAuth::AccessToken)
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
it "should call through to the master app" do
|
|
169
|
-
expect(last_response.body).to eq("true")
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
describe "/auth/{name}/callback with expired session" do
|
|
175
|
-
before do
|
|
176
|
-
stub_request(:post, "https://api.example.org/oauth/access_token").
|
|
177
|
-
to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
|
|
178
|
-
get "/auth/example.org/callback", {:oauth_verifier => "dudeman"}, "rack.session" => {}
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
it "should call fail! with :session_expired" do
|
|
182
|
-
expect(last_request.env["omniauth.error"]).to be_kind_of(::OmniAuth::NoSessionError)
|
|
183
|
-
last_request.env["omniauth.error.type"] = :session_expired
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
end
|