omniauth-eauth-oauth2-ens 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b936db7367ae3813b4ff6fa2d62260dea06322300a92d6c9e5975112b0f35306
4
+ data.tar.gz: 6c4d19724d51791d3dcf3d717eeb9d59bd040e96853f6dcdd187c98fe40abb5b
5
+ SHA512:
6
+ metadata.gz: 7920902c8759a49a29e41c713905f06ffee3d6c487af6375d727666314c083230aa917c14ed3ef647de81e7d135dbfebe44a3db05940a1f7e543160000bb5ee5
7
+ data.tar.gz: f28fd2baec7698662d03f0b0f0c4d31e3daddabdfa4a603b6e4be84aec8a4328b4e11af8e166207f7258c6aa5520a1d88eb0cf80473e7ff09a5cc7a30fb3823e
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ coverage
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ dist: trusty
2
+
3
+ rvm:
4
+ - 2.1.10
5
+ - 2.2.9
6
+ - 2.3.6
7
+ - 2.4.3
8
+ - 2.5.0
9
+ - jruby-1.7.26
10
+ - rbx-3
11
+
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: rbx-3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-eauth.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ desc 'Run specs'
7
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module EauthOauth2
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/strategies/eauth_oauth2'
@@ -0,0 +1,54 @@
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
+ address: raw_info['address'],
33
+ ens: raw_info['ens']
34
+ }
35
+ end
36
+
37
+ extra do
38
+ { raw_info: raw_info }
39
+ end
40
+
41
+ def raw_info
42
+ @raw_info ||= access_token.get('/oauth/user').parsed
43
+ end
44
+
45
+ private
46
+
47
+ def callback_url
48
+ full_host + script_name + callback_path
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ OmniAuth.config.add_camelization 'eauthoauth2', 'EauthOauth2'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/eauth_oauth2'
@@ -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-ens"
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
@@ -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-oauth2-ens'
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,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-eauth-oauth2-ens
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pei-Chen Tsou
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-08 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.7.6
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Official OmniAuth strategy for Eauth.
146
+ test_files: []