omniauth-seznam-cz 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -10
- data/.travis.yml +1 -2
- data/README.md +1 -1
- data/bin/publish-gem.sh +5 -0
- data/lib/omniauth/seznam_cz/version.rb +1 -1
- data/lib/omniauth/strategies/seznam_cz.rb +5 -6
- data/spec/omniauth/strategies/seznam_cz_spec.rb +9 -243
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c648d155cac9a61f968db43ea6fc26ff6d665921fec222a48b66211673f9b7ad
|
4
|
+
data.tar.gz: 6c9334d0ff6cea90af56f1f2f24203ce9b655f7548f2aa76f6b0bcaabe2f9c9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca5180f1309200a762c9fd2c1fdad9d346730b96c2b43a4f4c186e8b8675c35edb689ca27cae35e91ae95fa55052b71a0e5eaad576685b92cd2beabfe0e2d8ea
|
7
|
+
data.tar.gz: 6651969510ae8717ed2e8018d2585198ed09ede87dfbdbeda4691094e00b4b5ca86573eafee8feb549831bd3e13917ea53ad3f5a746687e331ac1b8c91057341
|
data/.gitignore
CHANGED
@@ -1,22 +1,13 @@
|
|
1
1
|
*.gem
|
2
|
-
*.rbc
|
3
2
|
.bundle
|
4
3
|
.config
|
5
|
-
.yardoc
|
6
4
|
.ruby-gemset
|
7
5
|
.ruby-version
|
8
6
|
.rvmrc
|
9
|
-
Gemfile.lock
|
10
|
-
InstalledFiles
|
11
|
-
_yardoc
|
12
|
-
coverage
|
13
|
-
doc/
|
14
|
-
lib/bundler/man
|
15
|
-
pkg
|
16
7
|
rdoc
|
17
8
|
spec/reports
|
18
9
|
test/tmp
|
19
10
|
test/version_tmp
|
20
11
|
tmp
|
21
|
-
.powenv
|
22
12
|
.idea/
|
13
|
+
Gemfile.lock
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/omniauth-seznam-cz.svg)](https://badge.fury.io/rb/omniauth-seznam-cz)
|
2
|
-
[![Build Status](https://travis-ci.com/
|
2
|
+
[![Build Status](https://app.travis-ci.com/honzasterba/omniauth-seznam-cz.svg?branch=main)](https://app.travis-ci.com/honzasterba/omniauth-seznam-cz)
|
3
3
|
|
4
4
|
# OmniAuth Seznam.cz Strategy
|
5
5
|
|
data/bin/publish-gem.sh
ADDED
@@ -6,23 +6,22 @@ require 'uri'
|
|
6
6
|
|
7
7
|
module OmniAuth
|
8
8
|
module Strategies
|
9
|
-
# Main class for Seznam.cz strategy.
|
10
9
|
class SeznamCz < OmniAuth::Strategies::OAuth2
|
11
10
|
ALLOWED_ISSUERS = ['login.szn.cz'].freeze
|
12
11
|
BASE_SCOPES = %w[identity contact-phone avatar].freeze
|
13
12
|
DEFAULT_SCOPE = 'identity'
|
14
13
|
USER_INFO_URL = 'https://login.szn.cz/api/v1/user'
|
15
|
-
IMAGE_SIZE_REGEXP = /(s\d+(-c)?)|(w\d+-h\d+(-c)?)|(w\d+(-c)?)|(h\d+(-c)?)|c/
|
16
14
|
|
17
15
|
option :name, 'seznam_cz'
|
18
16
|
option :skip_image_info, true
|
19
|
-
option :authorize_options, %i[redirect_uri]
|
17
|
+
option :authorize_options, %i[scope state redirect_uri]
|
20
18
|
option :authorized_client_ids, []
|
21
19
|
|
22
20
|
option :client_options,
|
23
|
-
site: 'https://login.szn.cz
|
24
|
-
authorize_url: '
|
25
|
-
token_url: '/token'
|
21
|
+
site: 'https://login.szn.cz',
|
22
|
+
authorize_url: '/api/v1/oauth/auth',
|
23
|
+
token_url: '/api/v1/oauth/token',
|
24
|
+
auth_scheme: :request_body
|
26
25
|
|
27
26
|
def authorize_params
|
28
27
|
super.tap do |params|
|
@@ -31,15 +31,15 @@ describe OmniAuth::Strategies::SeznamCz do
|
|
31
31
|
|
32
32
|
describe '#client_options' do
|
33
33
|
it 'has correct site' do
|
34
|
-
expect(subject.client.site).to eq('https://
|
34
|
+
expect(subject.client.site).to eq('https://login.szn.cz')
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'has correct authorize_url' do
|
38
|
-
expect(subject.client.options[:authorize_url]).to eq('
|
38
|
+
expect(subject.client.options[:authorize_url]).to eq('/api/v1/oauth/auth')
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'has correct token_url' do
|
42
|
-
expect(subject.client.options[:token_url]).to eq('/token')
|
42
|
+
expect(subject.client.options[:token_url]).to eq('/api/v1/oauth/token')
|
43
43
|
end
|
44
44
|
|
45
45
|
describe 'overrides' do
|
@@ -80,13 +80,6 @@ describe OmniAuth::Strategies::SeznamCz do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
describe '#authorize_options' do
|
83
|
-
%i[access_type hd login_hint prompt scope state device_id device_name].each do |k|
|
84
|
-
it "should support #{k}" do
|
85
|
-
@options = { k => 'http://someval' }
|
86
|
-
expect(subject.authorize_params[k.to_s]).to eq('http://someval')
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
83
|
describe 'redirect_uri' do
|
91
84
|
it 'should default to nil' do
|
92
85
|
@options = {}
|
@@ -99,116 +92,24 @@ describe OmniAuth::Strategies::SeznamCz do
|
|
99
92
|
end
|
100
93
|
end
|
101
94
|
|
102
|
-
describe 'access_type' do
|
103
|
-
it 'should default to "offline"' do
|
104
|
-
@options = {}
|
105
|
-
expect(subject.authorize_params['access_type']).to eq('offline')
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'should set the access_type parameter if present' do
|
109
|
-
@options = { access_type: 'online' }
|
110
|
-
expect(subject.authorize_params['access_type']).to eq('online')
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe 'hd' do
|
115
|
-
it 'should default to nil' do
|
116
|
-
expect(subject.authorize_params['hd']).to eq(nil)
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'should set the hd (hosted domain) parameter if present' do
|
120
|
-
@options = { hd: 'example.com' }
|
121
|
-
expect(subject.authorize_params['hd']).to eq('example.com')
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should set the hd parameter and work with nil hd (gmail)' do
|
125
|
-
@options = { hd: nil }
|
126
|
-
expect(subject.authorize_params['hd']).to eq(nil)
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'should set the hd parameter to * if set (only allows G Suite emails)' do
|
130
|
-
@options = { hd: '*' }
|
131
|
-
expect(subject.authorize_params['hd']).to eq('*')
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe 'login_hint' do
|
136
|
-
it 'should default to nil' do
|
137
|
-
expect(subject.authorize_params['login_hint']).to eq(nil)
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'should set the login_hint parameter if present' do
|
141
|
-
@options = { login_hint: 'john@example.com' }
|
142
|
-
expect(subject.authorize_params['login_hint']).to eq('john@example.com')
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
describe 'prompt' do
|
147
|
-
it 'should default to nil' do
|
148
|
-
expect(subject.authorize_params['prompt']).to eq(nil)
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'should set the prompt parameter if present' do
|
152
|
-
@options = { prompt: 'consent select_account' }
|
153
|
-
expect(subject.authorize_params['prompt']).to eq('consent select_account')
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe 'request_visible_actions' do
|
158
|
-
it 'should default to nil' do
|
159
|
-
expect(subject.authorize_params['request_visible_actions']).to eq(nil)
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'should set the request_visible_actions parameter if present' do
|
163
|
-
@options = { request_visible_actions: 'something' }
|
164
|
-
expect(subject.authorize_params['request_visible_actions']).to eq('something')
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
describe 'include_granted_scopes' do
|
169
|
-
it 'should default to nil' do
|
170
|
-
expect(subject.authorize_params['include_granted_scopes']).to eq(nil)
|
171
|
-
end
|
172
|
-
|
173
|
-
it 'should set the include_granted_scopes parameter if present' do
|
174
|
-
@options = { include_granted_scopes: 'true' }
|
175
|
-
expect(subject.authorize_params['include_granted_scopes']).to eq('true')
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
95
|
describe 'scope' do
|
180
|
-
it 'should expand scope shortcuts' do
|
181
|
-
@options = { scope: 'calendar' }
|
182
|
-
expect(subject.authorize_params['scope']).to eq('https://www.googleapis.com/auth/calendar')
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'should leave base scopes as is' do
|
186
|
-
@options = { scope: 'profile' }
|
187
|
-
expect(subject.authorize_params['scope']).to eq('profile')
|
188
|
-
end
|
189
|
-
|
190
96
|
it 'should join scopes' do
|
191
97
|
@options = { scope: 'profile,email' }
|
192
|
-
expect(subject.authorize_params['scope']).to eq('profile
|
98
|
+
expect(subject.authorize_params['scope']).to eq('profile,email')
|
193
99
|
end
|
194
100
|
|
195
101
|
it 'should deal with whitespace when joining scopes' do
|
196
102
|
@options = { scope: 'profile, email' }
|
197
|
-
expect(subject.authorize_params['scope']).to eq('profile
|
103
|
+
expect(subject.authorize_params['scope']).to eq('profile,email')
|
198
104
|
end
|
199
105
|
|
200
|
-
it 'should set default scope to
|
201
|
-
expect(subject.authorize_params['scope']).to eq('
|
106
|
+
it 'should set default scope to identity' do
|
107
|
+
expect(subject.authorize_params['scope']).to eq('identity')
|
202
108
|
end
|
203
109
|
|
204
110
|
it 'should support space delimited scopes' do
|
205
111
|
@options = { scope: 'profile email' }
|
206
|
-
expect(subject.authorize_params['scope']).to eq('profile
|
207
|
-
end
|
208
|
-
|
209
|
-
it 'should support extremely badly formed scopes' do
|
210
|
-
@options = { scope: 'profile email,foo,steve yeah http://example.com' }
|
211
|
-
expect(subject.authorize_params['scope']).to eq('profile email https://www.googleapis.com/auth/foo https://www.googleapis.com/auth/steve https://www.googleapis.com/auth/yeah http://example.com')
|
112
|
+
expect(subject.authorize_params['scope']).to eq('profile,email')
|
212
113
|
end
|
213
114
|
end
|
214
115
|
|
@@ -238,7 +139,7 @@ describe OmniAuth::Strategies::SeznamCz do
|
|
238
139
|
end
|
239
140
|
|
240
141
|
describe 'request overrides' do
|
241
|
-
%i[
|
142
|
+
%i[scope state].each do |k|
|
242
143
|
context "authorize option #{k}" do
|
243
144
|
let(:request) { double('Request', params: { k.to_s => 'http://example.com' }, cookies: {}, env: {}) }
|
244
145
|
|
@@ -267,7 +168,6 @@ describe OmniAuth::Strategies::SeznamCz do
|
|
267
168
|
expect(subject.authorize_params['request_visible_actions']).to eq('something')
|
268
169
|
expect(subject.authorize_params['foo']).to eq('bar')
|
269
170
|
expect(subject.authorize_params['baz']).to eq('zip')
|
270
|
-
expect(subject.authorize_params['hd']).to eq('wow')
|
271
171
|
expect(subject.authorize_params['bad']).to eq(nil)
|
272
172
|
end
|
273
173
|
end
|
@@ -288,138 +188,4 @@ describe OmniAuth::Strategies::SeznamCz do
|
|
288
188
|
expect(subject.token_params['bad']).to eq(nil)
|
289
189
|
end
|
290
190
|
end
|
291
|
-
|
292
|
-
describe '#callback_url' do
|
293
|
-
let(:base_url) { 'https://example.com' }
|
294
|
-
|
295
|
-
it 'has the correct default callback path' do
|
296
|
-
allow(subject).to receive(:full_host) { base_url }
|
297
|
-
allow(subject).to receive(:script_name) { '' }
|
298
|
-
expect(subject.send(:callback_url)).to eq(base_url + '/auth/google_oauth2/callback')
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'should set the callback path with script_name if present' do
|
302
|
-
allow(subject).to receive(:full_host) { base_url }
|
303
|
-
allow(subject).to receive(:script_name) { '/v1' }
|
304
|
-
expect(subject.send(:callback_url)).to eq(base_url + '/v1/auth/google_oauth2/callback')
|
305
|
-
end
|
306
|
-
|
307
|
-
it 'should set the callback_path parameter if present' do
|
308
|
-
@options = { callback_path: '/auth/foo/callback' }
|
309
|
-
allow(subject).to receive(:full_host) { base_url }
|
310
|
-
allow(subject).to receive(:script_name) { '' }
|
311
|
-
expect(subject.send(:callback_url)).to eq(base_url + '/auth/foo/callback')
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
describe '#info' do
|
316
|
-
let(:client) do
|
317
|
-
OAuth2::Client.new('abc', 'def') do |builder|
|
318
|
-
builder.request :url_encoded
|
319
|
-
builder.adapter :test do |stub|
|
320
|
-
stub.get('/oauth2/v3/userinfo') { [200, { 'content-type' => 'application/json' }, response_hash.to_json] }
|
321
|
-
end
|
322
|
-
end
|
323
|
-
end
|
324
|
-
let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
|
325
|
-
before { allow(subject).to receive(:access_token).and_return(access_token) }
|
326
|
-
|
327
|
-
context 'with verified email' do
|
328
|
-
let(:response_hash) do
|
329
|
-
{ email: 'something@domain.invalid', email_verified: true }
|
330
|
-
end
|
331
|
-
|
332
|
-
it 'should return equal email and unverified_email' do
|
333
|
-
expect(subject.info[:email]).to eq('something@domain.invalid')
|
334
|
-
expect(subject.info[:unverified_email]).to eq('something@domain.invalid')
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
context 'with unverified email' do
|
339
|
-
let(:response_hash) do
|
340
|
-
{ email: 'something@domain.invalid', email_verified: false }
|
341
|
-
end
|
342
|
-
|
343
|
-
it 'should return nil email, and correct unverified email' do
|
344
|
-
expect(subject.info[:email]).to eq(nil)
|
345
|
-
expect(subject.info[:unverified_email]).to eq('something@domain.invalid')
|
346
|
-
end
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
describe '#extra' do
|
351
|
-
let(:client) do
|
352
|
-
OAuth2::Client.new('abc', 'def') do |builder|
|
353
|
-
builder.request :url_encoded
|
354
|
-
builder.adapter :test do |stub|
|
355
|
-
stub.get('/oauth2/v3/userinfo') { [200, { 'content-type' => 'application/json' }, '{"sub": "12345"}'] }
|
356
|
-
end
|
357
|
-
end
|
358
|
-
end
|
359
|
-
let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
|
360
|
-
|
361
|
-
before { allow(subject).to receive(:access_token).and_return(access_token) }
|
362
|
-
|
363
|
-
describe 'id_token' do
|
364
|
-
shared_examples 'id_token issued by valid issuer' do |issuer|
|
365
|
-
context 'when the id_token is passed into the access token' do
|
366
|
-
let(:token_info) do
|
367
|
-
{
|
368
|
-
'abc' => 'xyz',
|
369
|
-
'exp' => Time.now.to_i + 3600,
|
370
|
-
'nbf' => Time.now.to_i - 60,
|
371
|
-
'iat' => Time.now.to_i,
|
372
|
-
'aud' => 'appid',
|
373
|
-
'iss' => issuer
|
374
|
-
}
|
375
|
-
end
|
376
|
-
let(:id_token) { JWT.encode(token_info, 'secret') }
|
377
|
-
let(:access_token) { OAuth2::AccessToken.from_hash(client, 'id_token' => id_token) }
|
378
|
-
|
379
|
-
it 'should include id_token when set on the access_token' do
|
380
|
-
expect(subject.extra).to include(id_token: id_token)
|
381
|
-
end
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
it 'should include id_info when id_token is set on the access_token by default' do
|
386
|
-
expect(subject.extra).to include(id_info: token_info)
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
it_behaves_like 'id_token issued by valid issuer', 'accounts.google.com'
|
392
|
-
it_behaves_like 'id_token issued by valid issuer', 'https://accounts.google.com'
|
393
|
-
|
394
|
-
context 'when the id_token is missing' do
|
395
|
-
it 'should not include id_token' do
|
396
|
-
expect(subject.extra).not_to have_key(:id_token)
|
397
|
-
end
|
398
|
-
|
399
|
-
it 'should not include id_info' do
|
400
|
-
expect(subject.extra).not_to have_key(:id_info)
|
401
|
-
end
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
describe 'raw_info' do
|
406
|
-
context 'when skip_info is true' do
|
407
|
-
before { subject.options[:skip_info] = true }
|
408
|
-
|
409
|
-
it 'should not include raw_info' do
|
410
|
-
expect(subject.extra).not_to have_key(:raw_info)
|
411
|
-
end
|
412
|
-
end
|
413
|
-
|
414
|
-
context 'when skip_info is false' do
|
415
|
-
before { subject.options[:skip_info] = false }
|
416
|
-
|
417
|
-
it 'should include raw_info' do
|
418
|
-
expect(subject.extra[:raw_info]).to eq('sub' => '12345')
|
419
|
-
end
|
420
|
-
end
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
|
425
191
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-seznam-cz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Sterba
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- Gemfile
|
110
110
|
- README.md
|
111
111
|
- Rakefile
|
112
|
+
- bin/publish-gem.sh
|
112
113
|
- lib/omniauth-seznam-cz.rb
|
113
114
|
- lib/omniauth/seznam_cz.rb
|
114
115
|
- lib/omniauth/seznam_cz/version.rb
|