omniauth-cz-shop-platforms 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f9984d2d991ad71fe78baa870f609248b9e4c641fc7b4bdd295313001dada2b
4
- data.tar.gz: 04ede54a6fb8a491088342058aa82a5300d755287427cb742029a2d0c026ea1f
3
+ metadata.gz: bf68b9e2a7e724dd5b53df846c87d9e154cf2bdf7f7cdb64105e9b20ea544043
4
+ data.tar.gz: 14e9a2512249d2cd21ed863893fde6242934fc7389bb5b0b6cba29f3eecee383
5
5
  SHA512:
6
- metadata.gz: bb250e086ddf76deb65a67316ff90e619b77698dff4bc2d69bcc490df7b5c2f017a760fdb60a0bb153a6140a59bc5596e448b263dbfe604cf3414bbc4f4e96c6
7
- data.tar.gz: 2deecd6b28aa63fa4f9ddf11e3187a93d1b469302750bd71409bd56dd435ec13c8f510b40028c8760e682f28396ce1f5e9ead58c49836b6d1388b30ea908cdfe
6
+ metadata.gz: 914b67cd782bd54a757bdb94ad3949d5a64e565f37f213d85a9cba49d601848a522b945b4e88c1d8fe10c98e260bea2e45d82c75feeb1e559c35a9e5469f38f8
7
+ data.tar.gz: 7ab29862c4f1c65aa370e76a8cd78bb101581e25a8d91310fb1572201621528cc9734fbabc34e134556b9867f2f0f6cc9baa5b9c4eea8f176233b9f078eb30d3
data/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## 1.1.0 - 2022-04-11
5
+
6
+ ### Added
7
+ - added strategy for shoptet.cz
8
+
9
+ ### Deprecated
10
+ - Nothing.
11
+
12
+ ### Removed
13
+ - cleaned up webareal code
14
+
15
+ ### Fixed
16
+ - Nothing.
17
+
4
18
  ## 1.0.0 - 2022-03-20
5
19
 
6
20
  ### Added
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAuth
4
4
  module CzShopPlatforms
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'omniauth/strategies/web_areal'
4
+ require 'omniauth/strategies/shoptet'
@@ -0,0 +1,67 @@
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 Shoptet < OmniAuth::Strategies::OAuth2
11
+ DEFAULT_SCOPE = 'basic_eshop'
12
+ USER_INFO_PATH = '/action/OAuthServer/resource?method=getBasicEshop'
13
+
14
+ option :name, 'shoptet'
15
+ option :scope, DEFAULT_SCOPE
16
+
17
+ option :client_options,
18
+ authorize_url: '/action/OAuthServer/authorize',
19
+ token_url: '/action/OAuthServer/token',
20
+ auth_scheme: :request_body
21
+ option :authorize_options, %i[scope]
22
+ option :token_options, %i[scope]
23
+
24
+ def client_site
25
+ if options.site
26
+ options.site
27
+ elsif request.params['shop_name']
28
+ shop_name = request.params['shop_name']
29
+ site = "https://#{shop_name}.myshoptet.com"
30
+ session['omniauth.shoptet.site'] = site
31
+ site
32
+ elsif session['omniauth.shoptet.site']
33
+ session['omniauth.shoptet.site']
34
+ else
35
+ raise 'Cannot determine client site, set :site option or shop_name request param.'
36
+ end
37
+ end
38
+
39
+ def client
40
+ client_options = deep_symbolize(options.client_options)
41
+ client_options[:site] = client_site
42
+ ::OAuth2::Client.new(options.client_id, options.client_secret, client_options)
43
+ end
44
+
45
+ uid { raw_info['data']['user']['email'] }
46
+
47
+ info do
48
+ {
49
+ email: raw_info['data']['user']['email'],
50
+ store: raw_info['data']['user']['project']
51
+ }
52
+ end
53
+
54
+ extra do
55
+ { 'raw_info' => raw_info }
56
+ end
57
+
58
+ def callback_url
59
+ full_host + callback_path
60
+ end
61
+
62
+ def raw_info
63
+ @raw_info ||= access_token.get(USER_INFO_PATH).parsed
64
+ end
65
+ end
66
+ end
67
+ end
@@ -12,8 +12,8 @@ module OmniAuth
12
12
  USER_INFO_URL = 'https://marketplace.webareal.cz/api/user/about'
13
13
 
14
14
  option :name, 'web_areal'
15
- option :authorize_options, %i[scope state redirect_uri]
16
- option :authorized_client_ids, []
15
+ option :authorize_options, %i[scope]
16
+ option :scope, DEFAULT_SCOPE
17
17
 
18
18
  option :client_options,
19
19
  site: 'https://marketplace.webareal.cz',
@@ -21,16 +21,6 @@ module OmniAuth
21
21
  token_url: '/api/token',
22
22
  auth_scheme: :request_body
23
23
 
24
- def authorize_params
25
- super.tap do |params|
26
- options[:authorize_options].each do |k|
27
- params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
28
- end
29
- params[:scope] ||= DEFAULT_SCOPE
30
- session['omniauth.state'] = params[:state] if params[:state]
31
- end
32
- end
33
-
34
24
  uid { raw_info['user'] }
35
25
 
36
26
  info do
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'json'
5
+ require 'omniauth-cz-shop-platforms'
6
+ require 'stringio'
7
+
8
+ describe OmniAuth::Strategies::Shoptet do
9
+ let(:request) { double('Request', params: @params || {}, cookies: {}, env: { 'rack.session' => @session || {} }) }
10
+ let(:app) do
11
+ lambda do
12
+ [200, {}, ['Hello.']]
13
+ end
14
+ end
15
+
16
+ subject do
17
+ OmniAuth::Strategies::Shoptet.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
18
+ allow(strategy).to receive(:request) do
19
+ request
20
+ end
21
+ allow(strategy).to receive(:session) do
22
+ request.env['rack.session']
23
+ end
24
+ end
25
+ end
26
+
27
+ before do
28
+ OmniAuth.config.test_mode = true
29
+ end
30
+
31
+ after do
32
+ OmniAuth.config.test_mode = false
33
+ end
34
+
35
+ describe 'missing site information' do
36
+ it 'should raise error' do
37
+ expect { subject.client }.to raise_error(/Cannot determine client site/)
38
+ end
39
+ end
40
+
41
+ describe 'site override' do
42
+ before do
43
+ @options = { site: 'https://custom.site' }
44
+ end
45
+
46
+ it 'has site from options' do
47
+ expect(subject.client.site).to eq('https://custom.site')
48
+ end
49
+ end
50
+
51
+ describe 'on authorize' do
52
+ before do
53
+ @params = { 'shop_name' => 'awesome-shop' }
54
+ end
55
+
56
+ describe '#client_options' do
57
+ it 'has correct authorize_url' do
58
+ expect(subject.client.options[:authorize_url]).to eq('/action/OAuthServer/authorize')
59
+ end
60
+
61
+ it 'has correct token_url' do
62
+ expect(subject.client.options[:token_url]).to eq('/action/OAuthServer/token')
63
+ end
64
+
65
+ it 'has site from request param' do
66
+ expect(subject.client.site).to eq('https://awesome-shop.myshoptet.com')
67
+ end
68
+
69
+ describe 'overrides' do
70
+ it 'should allow overriding the authorize_url' do
71
+ @options = { client_options: { 'authorize_url' => 'https://example.com' } }
72
+ expect(subject.client.options[:authorize_url]).to eq('https://example.com')
73
+ end
74
+
75
+ it 'should allow overriding the token_url' do
76
+ @options = { client_options: { 'token_url' => 'https://example.com' } }
77
+ expect(subject.client.options[:token_url]).to eq('https://example.com')
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ describe '#authorize_params' do
84
+ it 'should include any authorize params passed in the :authorize_params option' do
85
+ @options = { authorize_params: { request_visible_actions: 'something', foo: 'bar', baz: 'zip' }, hd: 'wow', bad: 'not_included' }
86
+ expect(subject.authorize_params['request_visible_actions']).to eq('something')
87
+ expect(subject.authorize_params['foo']).to eq('bar')
88
+ expect(subject.authorize_params['baz']).to eq('zip')
89
+ expect(subject.authorize_params['bad']).to eq(nil)
90
+ end
91
+ end
92
+
93
+ describe 'token phase' do
94
+ before do
95
+ @session = { 'omniauth.shoptet.site' => 'SITE_SESSION' }
96
+ end
97
+
98
+ it 'should take client site from session' do
99
+ expect(subject.client.site).to eq('SITE_SESSION')
100
+ end
101
+ end
102
+
103
+ describe '#token_params' do
104
+ it 'should include any token params passed in the :token_params option' do
105
+ @options = { token_params: { foo: 'bar', baz: 'zip' } }
106
+ expect(subject.token_params['foo']).to eq('bar')
107
+ expect(subject.token_params['baz']).to eq('zip')
108
+ end
109
+ end
110
+
111
+ describe '#token_options' do
112
+ it 'should include top-level options that are marked as :token_options' do
113
+ @options = { token_options: %i[scope foo], scope: 'bar', foo: 'baz', bad: 'not_included' }
114
+ expect(subject.token_params['scope']).to eq('bar')
115
+ expect(subject.token_params['foo']).to eq('baz')
116
+ expect(subject.token_params['bad']).to eq(nil)
117
+ end
118
+ end
119
+ end
@@ -79,68 +79,6 @@ describe OmniAuth::Strategies::WebAreal do
79
79
  end
80
80
  end
81
81
 
82
- describe '#authorize_options' do
83
- describe 'redirect_uri' do
84
- it 'should default to nil' do
85
- @options = {}
86
- expect(subject.authorize_params['redirect_uri']).to eq(nil)
87
- end
88
-
89
- it 'should set the redirect_uri parameter if present' do
90
- @options = { redirect_uri: 'https://example.com' }
91
- expect(subject.authorize_params['redirect_uri']).to eq('https://example.com')
92
- end
93
- end
94
-
95
- describe 'state' do
96
- it 'should set the state parameter' do
97
- @options = { state: 'some_state' }
98
- expect(subject.authorize_params['state']).to eq('some_state')
99
- expect(subject.authorize_params[:state]).to eq('some_state')
100
- expect(subject.session['omniauth.state']).to eq('some_state')
101
- end
102
-
103
- it 'should set the omniauth.state dynamically' do
104
- allow(subject).to receive(:request) { double('Request', params: { 'state' => 'some_state' }, env: {}) }
105
- expect(subject.authorize_params['state']).to eq('some_state')
106
- expect(subject.authorize_params[:state]).to eq('some_state')
107
- expect(subject.session['omniauth.state']).to eq('some_state')
108
- end
109
- end
110
-
111
- describe 'overrides' do
112
- it 'should include top-level options that are marked as :authorize_options' do
113
- @options = { authorize_options: %i[scope foo request_visible_actions], scope: 'http://bar', foo: 'baz', hd: 'wow', request_visible_actions: 'something' }
114
- expect(subject.authorize_params['scope']).to eq('http://bar')
115
- expect(subject.authorize_params['foo']).to eq('baz')
116
- expect(subject.authorize_params['hd']).to eq(nil)
117
- expect(subject.authorize_params['request_visible_actions']).to eq('something')
118
- end
119
-
120
- describe 'request overrides' do
121
- %i[scope state].each do |k|
122
- context "authorize option #{k}" do
123
- let(:request) { double('Request', params: { k.to_s => 'http://example.com' }, cookies: {}, env: {}) }
124
-
125
- it "should set the #{k} authorize option dynamically in the request" do
126
- @options = { k: '' }
127
- expect(subject.authorize_params[k.to_s]).to eq('http://example.com')
128
- end
129
- end
130
- end
131
-
132
- describe 'custom authorize_options' do
133
- let(:request) { double('Request', params: { 'foo' => 'something' }, cookies: {}, env: {}) }
134
-
135
- it 'should support request overrides from custom authorize_options' do
136
- @options = { authorize_options: [:foo], foo: '' }
137
- expect(subject.authorize_params['foo']).to eq('something')
138
- end
139
- end
140
- end
141
- end
142
- end
143
-
144
82
  describe '#authorize_params' do
145
83
  it 'should include any authorize params passed in the :authorize_params option' do
146
84
  @options = { authorize_params: { request_visible_actions: 'something', foo: 'bar', baz: 'zip' }, hd: 'wow', bad: 'not_included' }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-cz-shop-platforms
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.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-03-21 00:00:00.000000000 Z
11
+ date: 2022-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -113,8 +113,10 @@ files:
113
113
  - lib/omniauth-cz-shop-platforms.rb
114
114
  - lib/omniauth/cz_shop_platforms.rb
115
115
  - lib/omniauth/cz_shop_platforms/version.rb
116
+ - lib/omniauth/strategies/shoptet.rb
116
117
  - lib/omniauth/strategies/web_areal.rb
117
118
  - omniauth-cz-shop-platforms.gemspec
119
+ - spec/omniauth/strategies/shoptet_spec.rb
118
120
  - spec/omniauth/strategies/web_areal_spec.rb
119
121
  - spec/rubocop_spec.rb
120
122
  - spec/spec_helper.rb