omniauth-cz-shop-platforms 1.0.0

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: 9f9984d2d991ad71fe78baa870f609248b9e4c641fc7b4bdd295313001dada2b
4
+ data.tar.gz: 04ede54a6fb8a491088342058aa82a5300d755287427cb742029a2d0c026ea1f
5
+ SHA512:
6
+ metadata.gz: bb250e086ddf76deb65a67316ff90e619b77698dff4bc2d69bcc490df7b5c2f017a760fdb60a0bb153a6140a59bc5596e448b263dbfe604cf3414bbc4f4e96c6
7
+ data.tar.gz: 2deecd6b28aa63fa4f9ddf11e3187a93d1b469302750bd71409bd56dd435ec13c8f510b40028c8760e682f28396ce1f5e9ead58c49836b6d1388b30ea908cdfe
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ *.gem
2
+ .bundle
3
+ .config
4
+ .ruby-gemset
5
+ .ruby-version
6
+ .rvmrc
7
+ rdoc
8
+ spec/reports
9
+ test/tmp
10
+ test/version_tmp
11
+ tmp
12
+ .idea/
13
+ Gemfile.lock
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,5 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - '2.7.4'
5
+ - '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-03-20
5
+
6
+ ### Added
7
+ - added strategy for webareal.cz
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,28 @@
1
+ [![Gem Version](https://badge.fury.io/rb/omniauth-cz-shop-platforms.svg)](https://badge.fury.io/rb/omniauth-cz-shop-platforms)
2
+ [![Build Status](https://app.travis-ci.com/honzasterba/omniauth-cz-shop-platforms.svg?branch=main)](https://app.travis-ci.com/honzasterba/omniauth-cz-shop-platforms)
3
+
4
+ # OmniAuth Strategies for czech eshop platforms
5
+
6
+ Strategy to authenticate with various czech shop platforms
7
+
8
+ - [WebAreal.cz](https://marketplace.webareal.cz/doc/user-settings)
9
+
10
+ ## Installation
11
+
12
+ Add to your `Gemfile`:
13
+
14
+ ```ruby
15
+ gem 'omniauth-cz-shop-platforms'
16
+ ```
17
+
18
+ Then `bundle install`.
19
+
20
+ ## License
21
+
22
+ Copyright (c) 2018 by Jan Sterba
23
+
24
+ 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:
25
+
26
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
27
+
28
+ 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,5 @@
1
+ #!/bin/bash
2
+
3
+ rm *.gem
4
+ gem build omniauth-cz-shop-platforms.gemspec
5
+ gem push omniauth-cz-shop-platforms-*.gem
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module CzShopPlatforms
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/strategies/web_areal'
@@ -0,0 +1,56 @@
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 WebAreal < OmniAuth::Strategies::OAuth2
11
+ DEFAULT_SCOPE = 'USER_INFO'
12
+ USER_INFO_URL = 'https://marketplace.webareal.cz/api/user/about'
13
+
14
+ option :name, 'web_areal'
15
+ option :authorize_options, %i[scope state redirect_uri]
16
+ option :authorized_client_ids, []
17
+
18
+ option :client_options,
19
+ site: 'https://marketplace.webareal.cz',
20
+ authorize_url: '/user-auth',
21
+ token_url: '/api/token',
22
+ auth_scheme: :request_body
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
+ uid { raw_info['user'] }
35
+
36
+ info do
37
+ {
38
+ email: raw_info['user'],
39
+ stores: raw_info['stores']
40
+ }
41
+ end
42
+
43
+ extra do
44
+ { 'raw_info' => raw_info }
45
+ end
46
+
47
+ def callback_url
48
+ full_host + callback_path
49
+ end
50
+
51
+ def raw_info
52
+ @raw_info ||= access_token.get(USER_INFO_URL).parsed
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/cz_shop_platforms'
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path(
4
+ File.join('..', 'lib', 'omniauth', 'cz_shop_platforms', 'version'),
5
+ __FILE__
6
+ )
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = 'omniauth-cz-shop-platforms'
10
+ gem.version = OmniAuth::CzShopPlatforms::VERSION
11
+ gem.license = 'MIT'
12
+ gem.summary = %(A collection of strategies for OmniAuth)
13
+ gem.description = %(This allows you to login via multiple Czech e-commerce platforms with your ruby app.)
14
+ gem.authors = ['Jan Sterba']
15
+ gem.email = ['info@jansterba.com']
16
+ gem.homepage = 'https://github.com/honzasterba/omniauth-cz-shop-platforms'
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,170 @@
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::WebAreal 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::WebAreal.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://marketplace.webareal.cz')
35
+ end
36
+
37
+ it 'has correct authorize_url' do
38
+ expect(subject.client.options[:authorize_url]).to eq('/user-auth')
39
+ end
40
+
41
+ it 'has correct token_url' do
42
+ expect(subject.client.options[:token_url]).to eq('/api/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
+ 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
+ describe '#authorize_params' do
145
+ it 'should include any authorize params passed in the :authorize_params option' do
146
+ @options = { authorize_params: { request_visible_actions: 'something', foo: 'bar', baz: 'zip' }, hd: 'wow', bad: 'not_included' }
147
+ expect(subject.authorize_params['request_visible_actions']).to eq('something')
148
+ expect(subject.authorize_params['foo']).to eq('bar')
149
+ expect(subject.authorize_params['baz']).to eq('zip')
150
+ expect(subject.authorize_params['bad']).to eq(nil)
151
+ end
152
+ end
153
+
154
+ describe '#token_params' do
155
+ it 'should include any token params passed in the :token_params option' do
156
+ @options = { token_params: { foo: 'bar', baz: 'zip' } }
157
+ expect(subject.token_params['foo']).to eq('bar')
158
+ expect(subject.token_params['baz']).to eq('zip')
159
+ end
160
+ end
161
+
162
+ describe '#token_options' do
163
+ it 'should include top-level options that are marked as :token_options' do
164
+ @options = { token_options: %i[scope foo], scope: 'bar', foo: 'baz', bad: 'not_included' }
165
+ expect(subject.token_params['scope']).to eq('bar')
166
+ expect(subject.token_params['foo']).to eq('baz')
167
+ expect(subject.token_params['bad']).to eq(nil)
168
+ end
169
+ end
170
+ 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,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-cz-shop-platforms
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jan Sterba
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-03-21 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: This allows you to login via multiple Czech e-commerce platforms with
98
+ 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
+ - bin/publish-gem.sh
113
+ - lib/omniauth-cz-shop-platforms.rb
114
+ - lib/omniauth/cz_shop_platforms.rb
115
+ - lib/omniauth/cz_shop_platforms/version.rb
116
+ - lib/omniauth/strategies/web_areal.rb
117
+ - omniauth-cz-shop-platforms.gemspec
118
+ - spec/omniauth/strategies/web_areal_spec.rb
119
+ - spec/rubocop_spec.rb
120
+ - spec/spec_helper.rb
121
+ homepage: https://github.com/honzasterba/omniauth-cz-shop-platforms
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '2.7'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubygems_version: 3.1.4
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: A collection of strategies for OmniAuth
144
+ test_files: []