omniauth-seznam-cz 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: f009f7470aef979d8104389d3beb5e477bd09fa974da325913c22dbaafa84959
4
+ data.tar.gz: 495f8ce948f74219cda3be1df8eb6465a3bd3b5be36b72405f712242c73cc8ca
5
+ SHA512:
6
+ metadata.gz: '09c096615acd0f366d707812bc2e1faf78277b57636db68dd2f31e1b9fe3dc1a06931e32c6a40f59fc2f0f6a32a769365ccc0fc58075482ae911b69c5516fed4'
7
+ data.tar.gz: ab3cb2cb209b02e19f7e7d39aa8a9cc3e283f1de54b446f5f6ef2bd4acbd06ee67025fa96aa2156519b90eeaf20d6f5be2e73f20f5c299fd86c5658ab54961ae
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .ruby-gemset
7
+ .ruby-version
8
+ .rvmrc
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
21
+ .powenv
22
+ .idea/
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ Metrics/ClassLength:
2
+ Enabled: false
3
+ Metrics/AbcSize:
4
+ Enabled: false
5
+ Metrics/BlockLength:
6
+ ExcludedMethods: ['describe', 'context', 'shared_examples']
7
+ Metrics/CyclomaticComplexity:
8
+ Enabled: false
9
+ Metrics/LineLength:
10
+ Enabled: false
11
+ Metrics/MethodLength:
12
+ Enabled: false
13
+ Metrics/PerceivedComplexity:
14
+ Enabled: false
15
+ Naming:
16
+ Enabled: false
17
+ Style/MutableConstant:
18
+ Enabled: false
19
+ Gemspec/RequiredRubyVersion:
20
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - '2.7.2'
5
+ - '2.7.6'
6
+ - '3.0.0'
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## 1.0.0 - 2022-01-12
5
+
6
+ ### Added
7
+ - copied from https://github.com/zquestz/omniauth-google-oauth2
8
+
9
+ ### Deprecated
10
+ - Nothing.
11
+
12
+ ### Removed
13
+ - Nothing.
14
+
15
+ ### Fixed
16
+ - Nothing.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/README.md ADDED
@@ -0,0 +1,79 @@
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/zquestz/omniauth-seznam-cz.svg)](https://travis-ci.com/zquestz/omniauth-seznam-cz)
3
+
4
+ # OmniAuth Seznam.cz Strategy
5
+
6
+ Strategy to authenticate with Seznam.cz in OmniAuth.
7
+
8
+ Get your API key at: https://vyvojari.seznam.cz/oauth/admin Note the Client ID and the Client Secret.
9
+
10
+ For more details, read the Seznam.cz docs: https://vyvojari.seznam.cz/oauth
11
+
12
+ ## Installation
13
+
14
+ Add to your `Gemfile`:
15
+
16
+ ```ruby
17
+ gem 'omniauth-seznam-cz'
18
+ ```
19
+
20
+ Then `bundle install`.
21
+
22
+ ## Usage
23
+
24
+ Here's an example for adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
25
+
26
+ ```ruby
27
+ Rails.application.config.middleware.use OmniAuth::Builder do
28
+ provider :seznam_cz, ENV['SEZNAM_CLIENT_ID'], ENV['SEZNAM_CLIENT_SECRET']
29
+ end
30
+ ```
31
+
32
+ You can now access the OmniAuth Seznam.cz URL: `/auth/seznam_cz`
33
+
34
+ NOTE: While developing your application, if you change the scope in the initializer you will need to restart your app server.
35
+
36
+ ## Configuration
37
+
38
+ You can configure several options, which you pass in to the `provider` method via a hash:
39
+
40
+ * `scope`: A comma-separated list of permissions you want to request from the user.
41
+
42
+ * `redirect_uri`: Override the redirect_uri used by the gem.
43
+
44
+ ## Auth Hash
45
+
46
+ Here's an example of an authentication hash available in the callback by accessing `request.env['omniauth.auth']`:
47
+
48
+ ```ruby
49
+ {
50
+ "provider" => "seznam_cz",
51
+ "uid" => "100000000000000000000",
52
+ "info" => {
53
+ "name" => "John Smith",
54
+ "email" => "john@example.com",
55
+ "first_name" => "John",
56
+ "last_name" => "Smith",
57
+ "image" => "https://lh4.googleusercontent.com/photo.jpg",
58
+ "urls" => {
59
+ "google" => "https://plus.google.com/+JohnSmith"
60
+ }
61
+ },
62
+ "credentials" => {
63
+ "token" => "TOKEN",
64
+ "refresh_token" => "REFRESH_TOKEN",
65
+ "expires_at" => 1496120719,
66
+ "expires" => true
67
+ }
68
+ }
69
+ ```
70
+
71
+ ## License
72
+
73
+ Copyright (c) 2018 by Jan Sterba
74
+
75
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
76
+
77
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
78
+
79
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join('bundler', 'gem_tasks')
4
+ require File.join('rspec', 'core', 'rake_task')
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module SeznamCz
5
+ VERSION = '0.0.1'
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/strategies/seznam_cz'
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oauth2'
4
+ require 'omniauth/strategies/oauth2'
5
+ require 'uri'
6
+
7
+ module OmniAuth
8
+ module Strategies
9
+ # Main class for Seznam.cz strategy.
10
+ class SeznamCz < OmniAuth::Strategies::OAuth2
11
+ ALLOWED_ISSUERS = ['login.szn.cz'].freeze
12
+ BASE_SCOPES = %w[identity contact-phone avatar].freeze
13
+ DEFAULT_SCOPE = 'identity'
14
+ 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
+
17
+ option :name, 'seznam_cz'
18
+ option :skip_image_info, true
19
+ option :authorize_options, %i[redirect_uri]
20
+ option :authorized_client_ids, []
21
+
22
+ option :client_options,
23
+ site: 'https://login.szn.cz/api/v1/oauth',
24
+ authorize_url: 'https://login.szn.cz/api/v1/oauth/auth',
25
+ token_url: '/token'
26
+
27
+ def authorize_params
28
+ super.tap do |params|
29
+ options[:authorize_options].each do |k|
30
+ params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
31
+ end
32
+
33
+ params[:scope] = get_scope(params)
34
+ session['omniauth.state'] = params[:state] if params[:state]
35
+ end
36
+ end
37
+
38
+ uid { raw_info['sub'] }
39
+
40
+ info do
41
+ {
42
+ username: raw_info['username'],
43
+ email: raw_info['username'],
44
+ domain: raw_info['domain'],
45
+ firstname: raw_info['firstname'],
46
+ contact_phone: raw_info['contact-phone'],
47
+ avatar_url: raw_info['avatar-url']
48
+ }
49
+ end
50
+
51
+ extra do
52
+ { 'raw_info' => raw_info }
53
+ end
54
+
55
+ def raw_info
56
+ @raw_info ||= access_token.get(USER_INFO_URL).parsed
57
+ end
58
+
59
+ private
60
+
61
+ def get_scope(params)
62
+ raw_scope = params[:scope] || DEFAULT_SCOPE
63
+ scope_list = raw_scope.split(' ').map { |item| item.split(',') }.flatten
64
+ scope_list.join(',')
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/seznam_cz'
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path(
4
+ File.join('..', 'lib', 'omniauth', 'seznam_cz', 'version'),
5
+ __FILE__
6
+ )
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = 'omniauth-seznam-cz'
10
+ gem.version = OmniAuth::SeznamCz::VERSION
11
+ gem.license = 'MIT'
12
+ gem.summary = %(A Seznam.cz strategy for OmniAuth)
13
+ gem.description = %(A Seznam.cz strategy for OmniAuth. This allows you to login via Seznam.cz with your ruby app.)
14
+ gem.authors = ['Jan Sterba']
15
+ gem.email = ['info@jansterba.com']
16
+ gem.homepage = 'https://github.com/honzasterba/omniauth-seznam-cz'
17
+
18
+ gem.files = `git ls-files`.split("\n")
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.required_ruby_version = '>= 2.7'
22
+
23
+ gem.add_runtime_dependency 'oauth2', '~> 1.1'
24
+ gem.add_runtime_dependency 'omniauth', '~> 2.0'
25
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.7.1'
26
+
27
+ gem.add_development_dependency 'rake', '~> 12.0'
28
+ gem.add_development_dependency 'rspec', '~> 3.6'
29
+ gem.add_development_dependency 'rubocop', '~> 0.49'
30
+ end
@@ -0,0 +1,425 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'json'
5
+ require 'omniauth-seznam-cz'
6
+ require 'stringio'
7
+
8
+ describe OmniAuth::Strategies::SeznamCz do
9
+ let(:request) { double('Request', params: {}, cookies: {}, env: {}) }
10
+ let(:app) do
11
+ lambda do
12
+ [200, {}, ['Hello.']]
13
+ end
14
+ end
15
+
16
+ subject do
17
+ OmniAuth::Strategies::SeznamCz.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
18
+ allow(strategy).to receive(:request) do
19
+ request
20
+ end
21
+ end
22
+ end
23
+
24
+ before do
25
+ OmniAuth.config.test_mode = true
26
+ end
27
+
28
+ after do
29
+ OmniAuth.config.test_mode = false
30
+ end
31
+
32
+ describe '#client_options' do
33
+ it 'has correct site' do
34
+ expect(subject.client.site).to eq('https://oauth2.googleapis.com')
35
+ end
36
+
37
+ it 'has correct authorize_url' do
38
+ expect(subject.client.options[:authorize_url]).to eq('https://accounts.google.com/o/oauth2/auth')
39
+ end
40
+
41
+ it 'has correct token_url' do
42
+ expect(subject.client.options[:token_url]).to eq('/token')
43
+ end
44
+
45
+ describe 'overrides' do
46
+ context 'as strings' do
47
+ it 'should allow overriding the site' do
48
+ @options = { client_options: { 'site' => 'https://example.com' } }
49
+ expect(subject.client.site).to eq('https://example.com')
50
+ end
51
+
52
+ it 'should allow overriding the authorize_url' do
53
+ @options = { client_options: { 'authorize_url' => 'https://example.com' } }
54
+ expect(subject.client.options[:authorize_url]).to eq('https://example.com')
55
+ end
56
+
57
+ it 'should allow overriding the token_url' do
58
+ @options = { client_options: { 'token_url' => 'https://example.com' } }
59
+ expect(subject.client.options[:token_url]).to eq('https://example.com')
60
+ end
61
+ end
62
+
63
+ context 'as symbols' do
64
+ it 'should allow overriding the site' do
65
+ @options = { client_options: { site: 'https://example.com' } }
66
+ expect(subject.client.site).to eq('https://example.com')
67
+ end
68
+
69
+ it 'should allow overriding the authorize_url' do
70
+ @options = { client_options: { authorize_url: 'https://example.com' } }
71
+ expect(subject.client.options[:authorize_url]).to eq('https://example.com')
72
+ end
73
+
74
+ it 'should allow overriding the token_url' do
75
+ @options = { client_options: { token_url: 'https://example.com' } }
76
+ expect(subject.client.options[:token_url]).to eq('https://example.com')
77
+ end
78
+ end
79
+ end
80
+ end
81
+
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
+ describe 'redirect_uri' do
91
+ it 'should default to nil' do
92
+ @options = {}
93
+ expect(subject.authorize_params['redirect_uri']).to eq(nil)
94
+ end
95
+
96
+ it 'should set the redirect_uri parameter if present' do
97
+ @options = { redirect_uri: 'https://example.com' }
98
+ expect(subject.authorize_params['redirect_uri']).to eq('https://example.com')
99
+ end
100
+ end
101
+
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
+ 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
+ it 'should join scopes' do
191
+ @options = { scope: 'profile,email' }
192
+ expect(subject.authorize_params['scope']).to eq('profile email')
193
+ end
194
+
195
+ it 'should deal with whitespace when joining scopes' do
196
+ @options = { scope: 'profile, email' }
197
+ expect(subject.authorize_params['scope']).to eq('profile email')
198
+ end
199
+
200
+ it 'should set default scope to email,profile' do
201
+ expect(subject.authorize_params['scope']).to eq('email profile')
202
+ end
203
+
204
+ it 'should support space delimited scopes' do
205
+ @options = { scope: 'profile email' }
206
+ expect(subject.authorize_params['scope']).to eq('profile email')
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')
212
+ end
213
+ end
214
+
215
+ describe 'state' do
216
+ it 'should set the state parameter' do
217
+ @options = { state: 'some_state' }
218
+ expect(subject.authorize_params['state']).to eq('some_state')
219
+ expect(subject.authorize_params[:state]).to eq('some_state')
220
+ expect(subject.session['omniauth.state']).to eq('some_state')
221
+ end
222
+
223
+ it 'should set the omniauth.state dynamically' do
224
+ allow(subject).to receive(:request) { double('Request', params: { 'state' => 'some_state' }, env: {}) }
225
+ expect(subject.authorize_params['state']).to eq('some_state')
226
+ expect(subject.authorize_params[:state]).to eq('some_state')
227
+ expect(subject.session['omniauth.state']).to eq('some_state')
228
+ end
229
+ end
230
+
231
+ describe 'overrides' do
232
+ it 'should include top-level options that are marked as :authorize_options' do
233
+ @options = { authorize_options: %i[scope foo request_visible_actions], scope: 'http://bar', foo: 'baz', hd: 'wow', request_visible_actions: 'something' }
234
+ expect(subject.authorize_params['scope']).to eq('http://bar')
235
+ expect(subject.authorize_params['foo']).to eq('baz')
236
+ expect(subject.authorize_params['hd']).to eq(nil)
237
+ expect(subject.authorize_params['request_visible_actions']).to eq('something')
238
+ end
239
+
240
+ describe 'request overrides' do
241
+ %i[access_type hd login_hint prompt scope state].each do |k|
242
+ context "authorize option #{k}" do
243
+ let(:request) { double('Request', params: { k.to_s => 'http://example.com' }, cookies: {}, env: {}) }
244
+
245
+ it "should set the #{k} authorize option dynamically in the request" do
246
+ @options = { k: '' }
247
+ expect(subject.authorize_params[k.to_s]).to eq('http://example.com')
248
+ end
249
+ end
250
+ end
251
+
252
+ describe 'custom authorize_options' do
253
+ let(:request) { double('Request', params: { 'foo' => 'something' }, cookies: {}, env: {}) }
254
+
255
+ it 'should support request overrides from custom authorize_options' do
256
+ @options = { authorize_options: [:foo], foo: '' }
257
+ expect(subject.authorize_params['foo']).to eq('something')
258
+ end
259
+ end
260
+ end
261
+ end
262
+ end
263
+
264
+ describe '#authorize_params' do
265
+ it 'should include any authorize params passed in the :authorize_params option' do
266
+ @options = { authorize_params: { request_visible_actions: 'something', foo: 'bar', baz: 'zip' }, hd: 'wow', bad: 'not_included' }
267
+ expect(subject.authorize_params['request_visible_actions']).to eq('something')
268
+ expect(subject.authorize_params['foo']).to eq('bar')
269
+ expect(subject.authorize_params['baz']).to eq('zip')
270
+ expect(subject.authorize_params['hd']).to eq('wow')
271
+ expect(subject.authorize_params['bad']).to eq(nil)
272
+ end
273
+ end
274
+
275
+ describe '#token_params' do
276
+ it 'should include any token params passed in the :token_params option' do
277
+ @options = { token_params: { foo: 'bar', baz: 'zip' } }
278
+ expect(subject.token_params['foo']).to eq('bar')
279
+ expect(subject.token_params['baz']).to eq('zip')
280
+ end
281
+ end
282
+
283
+ describe '#token_options' do
284
+ it 'should include top-level options that are marked as :token_options' do
285
+ @options = { token_options: %i[scope foo], scope: 'bar', foo: 'baz', bad: 'not_included' }
286
+ expect(subject.token_params['scope']).to eq('bar')
287
+ expect(subject.token_params['foo']).to eq('baz')
288
+ expect(subject.token_params['bad']).to eq(nil)
289
+ end
290
+ 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
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ describe 'Rubocop' do
6
+ it 'should pass with no offenses detected' do
7
+ expect(`rubocop`).to include('no offenses detected')
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join('bundler', 'setup')
4
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-seznam-cz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jan Sterba
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: omniauth-oauth2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.7.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.7.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.49'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.49'
97
+ description: A Seznam.cz strategy for OmniAuth. This allows you to login via Seznam.cz
98
+ with your ruby app.
99
+ email:
100
+ - info@jansterba.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - CHANGELOG.md
109
+ - Gemfile
110
+ - README.md
111
+ - Rakefile
112
+ - lib/omniauth-seznam-cz.rb
113
+ - lib/omniauth/seznam_cz.rb
114
+ - lib/omniauth/seznam_cz/version.rb
115
+ - lib/omniauth/strategies/seznam_cz.rb
116
+ - omniauth-seznam-cz.gemspec
117
+ - spec/omniauth/strategies/seznam_cz_spec.rb
118
+ - spec/rubocop_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: https://github.com/honzasterba/omniauth-seznam-cz
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '2.7'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubygems_version: 3.1.4
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: A Seznam.cz strategy for OmniAuth
143
+ test_files: []