omniauth-eauth-oauth2 1.0.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 +7 -0
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/Rakefile +7 -0
- data/lib/omniauth/eauth_oauth2/version.rb +7 -0
- data/lib/omniauth/eauth_oauth2.rb +3 -0
- data/lib/omniauth/strategies/eauth_oauth2.rb +56 -0
- data/lib/omniauth-eauth-oauth2.rb +3 -0
- data/omniauth-eauth-oauth2.gemspec +29 -0
- data/spec/omniauth/strategies/eauth_oauth2_spec.rb +201 -0
- data/spec/spec_helper.rb +20 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c6708df6506c52fbb0b3609d5894145a46109f7f
|
4
|
+
data.tar.gz: 0e2244d86bfd0915e930c360160a1d26f4591f14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0a8433e77e55e3edac03401d05a64a371419ab7fd744029662b73cfca84a4013923bb5374202eb40e1a6fa9404a56365f57e7a6ece6b5f581c189f1903b5bd77
|
7
|
+
data.tar.gz: 91168966ceae50a30b594f418bbb2ec2333e0485f3f21a044116b660f130eea6fc94753727109a5dc5f2a86fba003e7cc4bc92b8e726d33c8776c8dce88449a6
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'omniauth/strategies/oauth2'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class EauthOauth2 < OmniAuth::Strategies::OAuth2
|
8
|
+
option :client_options, {
|
9
|
+
:site => 'https://eauth.pelith.com/',
|
10
|
+
:authorize_url => '/oauth/authorize',
|
11
|
+
:token_url => '/oauth/token'
|
12
|
+
}
|
13
|
+
|
14
|
+
def request_phase
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def authorize_params
|
19
|
+
super.tap do |params|
|
20
|
+
%w[scope client_options].each do |v|
|
21
|
+
if request.params[v]
|
22
|
+
params[v.to_sym] = request.params[v]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
uid { raw_info['id'].to_s }
|
29
|
+
|
30
|
+
info do
|
31
|
+
{
|
32
|
+
nickname: raw_info['login'],
|
33
|
+
name: raw_info['name'],
|
34
|
+
username: raw_info['username'],
|
35
|
+
email: raw_info['email']
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
extra do
|
40
|
+
{ raw_info: raw_info }
|
41
|
+
end
|
42
|
+
|
43
|
+
def raw_info
|
44
|
+
@raw_info ||= access_token.get('/oauth/user').parsed
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def callback_url
|
50
|
+
full_host + script_name + callback_path
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
OmniAuth.config.add_camelization 'eauthoauth2', 'EauthOauth2'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path(
|
4
|
+
File.join('..', 'lib', 'omniauth', 'eauth_oauth2', 'version'),
|
5
|
+
__FILE__
|
6
|
+
)
|
7
|
+
|
8
|
+
Gem::Specification.new do |gem|
|
9
|
+
gem.authors = ["Pei-Chen Tsou"]
|
10
|
+
gem.email = ["pei@pelith.com"]
|
11
|
+
gem.description = %q{Official OmniAuth strategy for Eauth.}
|
12
|
+
gem.summary = %q{Official OmniAuth strategy for Eauth.}
|
13
|
+
gem.homepage = "https://github.com/pelith/omniauth-eauth-oauth2"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
gem.files = `git ls-files`.split("\n")
|
18
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
gem.name = "omniauth-eauth-oauth2"
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
gem.version = OmniAuth::EauthOauth2::VERSION
|
22
|
+
|
23
|
+
gem.add_dependency 'omniauth', '~> 1.5'
|
24
|
+
gem.add_dependency 'omniauth-oauth2', '>= 1.4.0', '< 2.0'
|
25
|
+
gem.add_development_dependency 'rspec', '~> 3.5'
|
26
|
+
gem.add_development_dependency 'rack-test'
|
27
|
+
gem.add_development_dependency 'simplecov'
|
28
|
+
gem.add_development_dependency 'webmock'
|
29
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::EauthOauth2 do
|
4
|
+
let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
|
5
|
+
|
6
|
+
subject do
|
7
|
+
args = ['appid', 'secret', @options || {}].compact
|
8
|
+
OmniAuth::Strategies::EauthOauth2.new(*args).tap do |strategy|
|
9
|
+
allow(strategy).to receive(:request) {
|
10
|
+
request
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'client options' do
|
16
|
+
it 'should have correct site' do
|
17
|
+
expect(subject.options.client_options.site).to eq('https://eauth.pelith.com/')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have correct authorize url' do
|
21
|
+
expect(subject.options.client_options.authorize_url).to eq('/oauth/authorize')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have correct token_url' do
|
25
|
+
expect(subject.options.client_options.token_url).to eq('/oauth/token')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'info' do
|
30
|
+
before do
|
31
|
+
allow(subject).to receive(:raw_info).and_return(raw_info_hash)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should returns the nickname' do
|
35
|
+
expect(subject.info[:nickname]).to eq(raw_info_hash['screen_name'])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should returns the name' do
|
39
|
+
expect(subject.info[:name]).to eq(raw_info_hash['name'])
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should returns the email' do
|
43
|
+
expect(subject.info[:email]).to eq(raw_info_hash['email'])
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should returns the location' do
|
47
|
+
expect(subject.info[:location]).to eq(raw_info_hash['location'])
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should returns the description' do
|
51
|
+
expect(subject.info[:description]).to eq(raw_info_hash['description'])
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should returns the urls' do
|
55
|
+
expect(subject.info[:urls]['Website']).to eq(raw_info_hash['url'])
|
56
|
+
expect(subject.info[:urls]['Eauth']).to eq("https://demo.pelith.com/#{raw_info_hash['screen_name']}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'image_size option' do
|
61
|
+
context 'when user has an image' do
|
62
|
+
it 'should return image with size specified' do
|
63
|
+
@options = { :image_size => 'original' }
|
64
|
+
allow(subject).to receive(:raw_info).and_return(
|
65
|
+
{ 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' }
|
66
|
+
)
|
67
|
+
expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0.png')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should return bigger image when bigger size specified' do
|
71
|
+
@options = { :image_size => 'bigger' }
|
72
|
+
allow(subject).to receive(:raw_info).and_return(
|
73
|
+
{ 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' }
|
74
|
+
)
|
75
|
+
expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_bigger.png')
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should return secure image with size specified' do
|
79
|
+
@options = { :secure_image_url => 'true', :image_size => 'mini' }
|
80
|
+
allow(subject).to receive(:raw_info).and_return(
|
81
|
+
{ 'profile_image_url_https' => 'https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' }
|
82
|
+
)
|
83
|
+
expect(subject.info[:image]).to eq('https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_mini.png')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should return normal image by default' do
|
87
|
+
allow(subject).to receive(:raw_info).and_return(
|
88
|
+
{ 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' }
|
89
|
+
)
|
90
|
+
expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'skip_info option' do
|
96
|
+
context 'when skip info option is enabled' do
|
97
|
+
it 'should not include raw_info in extras hash' do
|
98
|
+
@options = { :skip_info => true }
|
99
|
+
allow(subject).to receive(:raw_info).and_return({:foo => 'bar'})
|
100
|
+
expect(subject.extra[:raw_info]).to eq(nil)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'request_phase' do
|
106
|
+
context 'with no request params set and x_auth_access_type specified' do
|
107
|
+
before do
|
108
|
+
allow(subject).to receive(:request).and_return(
|
109
|
+
double('Request', {:params => {'x_auth_access_type' => 'read'}})
|
110
|
+
)
|
111
|
+
allow(subject).to receive(:old_request_phase).and_return(:whatever)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should not break' do
|
115
|
+
expect { subject.request_phase }.not_to raise_error
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with no request params set and use_authorize options provided" do
|
120
|
+
before do
|
121
|
+
@options = { :use_authorize => true }
|
122
|
+
allow(subject).to receive(:request) do
|
123
|
+
double('Request', {:params => {} })
|
124
|
+
end
|
125
|
+
allow(subject).to receive(:old_request_phase) { :whatever }
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should switch authorize_path from authenticate to authorize" do
|
129
|
+
expect { subject.request_phase }.to change { subject.options.client_options.authorize_path }.from('/oauth/authenticate').to('/oauth/authorize')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'with a specified callback_url in the params' do
|
134
|
+
before do
|
135
|
+
params = { 'callback_url' => 'http://foo.dev/auth/eauth/foobar' }
|
136
|
+
allow(subject).to receive(:request) do
|
137
|
+
double('Request', :params => params)
|
138
|
+
end
|
139
|
+
allow(subject).to receive(:session) do
|
140
|
+
double('Session', :[] => { 'callback_url' => params['callback_url'] })
|
141
|
+
end
|
142
|
+
allow(subject).to receive(:old_request_phase) { :whatever }
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should use the callback_url' do
|
146
|
+
expect(subject.callback_url).to eq 'http://foo.dev/auth/eauth/foobar'
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should return the correct callback_path' do
|
150
|
+
expect(subject.callback_path).to eq '/auth/eauth/foobar'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'with no callback_url set' do
|
155
|
+
before do
|
156
|
+
allow(subject).to receive(:request) do
|
157
|
+
double('Request', :params => {})
|
158
|
+
end
|
159
|
+
allow(subject).to receive(:session) do
|
160
|
+
double('Session', :[] => {})
|
161
|
+
end
|
162
|
+
allow(subject).to receive(:old_request_phase) { :whatever }
|
163
|
+
allow(subject).to receive(:old_callback_url).and_return(:old_callback)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'callback_url should return nil' do
|
167
|
+
expect(subject.callback_url).to eq :old_callback
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should return the default callback_path value' do
|
171
|
+
expect(subject.callback_path).to eq '/auth/eauth/callback'
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context "with no request params set and force_login specified" do
|
176
|
+
before do
|
177
|
+
allow(subject).to receive(:request) do
|
178
|
+
double('Request', {:params => { 'force_login' => true } })
|
179
|
+
end
|
180
|
+
allow(subject).to receive(:old_request_phase) { :whatever }
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should change add force_login=true to authorize_params" do
|
184
|
+
expect { subject.request_phase }.to change {subject.options.authorize_params.force_login}.from(nil).to(true)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
private
|
191
|
+
|
192
|
+
def raw_info_hash
|
193
|
+
{
|
194
|
+
'screen_name' => 'foo',
|
195
|
+
'name' => 'Foo Bar',
|
196
|
+
'email' => 'foo@example.com',
|
197
|
+
'location' => 'India',
|
198
|
+
'description' => 'Developer',
|
199
|
+
'url' => 'example.com/foobar'
|
200
|
+
}
|
201
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start do
|
5
|
+
minimum_coverage(94.59)
|
6
|
+
end
|
7
|
+
require 'rspec'
|
8
|
+
require 'rack/test'
|
9
|
+
require 'webmock/rspec'
|
10
|
+
require 'omniauth'
|
11
|
+
require 'omniauth-eauth'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include WebMock::API
|
15
|
+
config.include Rack::Test::Methods
|
16
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
17
|
+
config.expect_with :rspec do |c|
|
18
|
+
c.syntax = :expect
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-eauth-oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pei-Chen Tsou
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: omniauth-oauth2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.4.0
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '2.0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.4.0
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.5'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.5'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rack-test
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: simplecov
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: webmock
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
description: Official OmniAuth strategy for Eauth.
|
104
|
+
email:
|
105
|
+
- pei@pelith.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- ".gitignore"
|
111
|
+
- ".rspec"
|
112
|
+
- ".travis.yml"
|
113
|
+
- Gemfile
|
114
|
+
- Rakefile
|
115
|
+
- lib/omniauth-eauth-oauth2.rb
|
116
|
+
- lib/omniauth/eauth_oauth2.rb
|
117
|
+
- lib/omniauth/eauth_oauth2/version.rb
|
118
|
+
- lib/omniauth/strategies/eauth_oauth2.rb
|
119
|
+
- omniauth-eauth-oauth2.gemspec
|
120
|
+
- spec/omniauth/strategies/eauth_oauth2_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: https://github.com/pelith/omniauth-eauth-oauth2
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.5.2.3
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Official OmniAuth strategy for Eauth.
|
146
|
+
test_files:
|
147
|
+
- spec/omniauth/strategies/eauth_oauth2_spec.rb
|
148
|
+
- spec/spec_helper.rb
|