omniauth-cz-shop-platforms 1.0.0 → 1.1.2
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 +4 -4
- data/CHANGELOG.md +28 -0
- data/lib/omniauth/cz_shop_platforms/version.rb +1 -1
- data/lib/omniauth/cz_shop_platforms.rb +1 -0
- data/lib/omniauth/strategies/shoptet.rb +67 -0
- data/lib/omniauth/strategies/web_areal.rb +2 -12
- data/spec/omniauth/strategies/shoptet_spec.rb +119 -0
- data/spec/omniauth/strategies/web_areal_spec.rb +0 -62
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f77783b8c5d35865170e1f25931123b7681ee4d92bc63f303c28eb2b5ee0cd1c
|
4
|
+
data.tar.gz: e0905656028ce24e5e457d8d2e0e84820c76432bf158644b3d4061bec4567384
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c1202c7990de0cd87e6ae2a47d25a931d7766246a3ce8222c6cafc6cd24c3f35ace9dafa1e1cff609b8d95d79f5751f002e5239fc6c1741f791f8664e77b631
|
7
|
+
data.tar.gz: e09801d6d0ffa71c627d99d8bf1c52b9956faa7b8d41700515ad504bd3c51c2e839890d78791a6580a9a467ebe680136c9211d33b374705855f4c72acd60761b
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,34 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## 1.1.2 - 2022-05-28
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- Nothing.
|
8
|
+
|
9
|
+
### Deprecated
|
10
|
+
- Nothing.
|
11
|
+
|
12
|
+
### Removed
|
13
|
+
- cleaned up webareal code
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
- Shoptet configuration requests full site, since domain can differ.
|
17
|
+
|
18
|
+
## 1.1.0 - 2022-04-11
|
19
|
+
|
20
|
+
### Added
|
21
|
+
- added strategy for shoptet.cz
|
22
|
+
|
23
|
+
### Deprecated
|
24
|
+
- Nothing.
|
25
|
+
|
26
|
+
### Removed
|
27
|
+
- cleaned up webareal code
|
28
|
+
|
29
|
+
### Fixed
|
30
|
+
- Nothing.
|
31
|
+
|
4
32
|
## 1.0.0 - 2022-03-20
|
5
33
|
|
6
34
|
### Added
|
@@ -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: 'authorize',
|
19
|
+
token_url: '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['shoptet_site']
|
28
|
+
shoptet_site = request.params['shoptet_site']
|
29
|
+
session['omniauth.shoptet.site'] = shoptet_site
|
30
|
+
shoptet_site
|
31
|
+
elsif session['omniauth.shoptet.site']
|
32
|
+
session['omniauth.shoptet.site']
|
33
|
+
else
|
34
|
+
raise 'Cannot determine client site, set :site option or shoptet_site request param or .'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def client
|
39
|
+
client_options = deep_symbolize(options.client_options)
|
40
|
+
client_options[:site] = client_site
|
41
|
+
::OAuth2::Client.new(options.client_id, options.client_secret, client_options)
|
42
|
+
end
|
43
|
+
|
44
|
+
uid { raw_info['user']['email'] }
|
45
|
+
|
46
|
+
info do
|
47
|
+
{
|
48
|
+
email: raw_info['user']['email'],
|
49
|
+
name: raw_info['user']['name'],
|
50
|
+
store: raw_info['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['data']
|
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
|
16
|
-
option :
|
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 = { 'shoptet_site' => 'https://awesome-shop.myshoptet.com/action/OAuthServer/' }
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#client_options' do
|
57
|
+
it 'has correct authorize_url' do
|
58
|
+
expect(subject.client.options[:authorize_url]).to eq('authorize')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'has correct token_url' do
|
62
|
+
expect(subject.client.options[:token_url]).to eq('token')
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'has site from request param' do
|
66
|
+
expect(subject.client.site).to eq('https://awesome-shop.myshoptet.com/action/OAuthServer/')
|
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.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Sterba
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-28 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
|
@@ -122,7 +124,7 @@ homepage: https://github.com/honzasterba/omniauth-cz-shop-platforms
|
|
122
124
|
licenses:
|
123
125
|
- MIT
|
124
126
|
metadata: {}
|
125
|
-
post_install_message:
|
127
|
+
post_install_message:
|
126
128
|
rdoc_options: []
|
127
129
|
require_paths:
|
128
130
|
- lib
|
@@ -137,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
139
|
- !ruby/object:Gem::Version
|
138
140
|
version: '0'
|
139
141
|
requirements: []
|
140
|
-
rubygems_version: 3.
|
141
|
-
signing_key:
|
142
|
+
rubygems_version: 3.2.32
|
143
|
+
signing_key:
|
142
144
|
specification_version: 4
|
143
145
|
summary: A collection of strategies for OmniAuth
|
144
146
|
test_files: []
|