sidekiq_web_google_auth 0.1.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: 3e7ecdfa630411d3ed7cf1fd03c661a03c12814b580b31864e23292399bf376a
4
+ data.tar.gz: 3e6b2ccbe836d569e9d9c4f2a7442da5f43763fc19249109d8ebf77bb4e7ac6e
5
+ SHA512:
6
+ metadata.gz: e56d58134ff8acd1a97525e617bede8d8133535ad842c53509e8baa0fe832881e2f513ec9baa2f12db195cfc595814c2e7adf89d68b64b5f1106bc8891153d23
7
+ data.tar.gz: e13b34d21104d577e4a1806da7eced089f3834531365351e23c796d943f473f6ca2409bc77de18202adac76b0fc89e0a9367462cc395fed23a03999e48a81ca5
@@ -0,0 +1,31 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+
9
+ # We want to run on external PRs, but not on our own internal PRs as they'll be run on push event
10
+ if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'umbrellio/sidekiq_web_google_auth'
11
+
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby: ["2.7", "3.0"]
16
+
17
+ name: ${{ matrix.ruby }}
18
+
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+
22
+ - uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+
27
+ - run: bundle exec rake
28
+
29
+ - uses: coverallsapp/github-action@v1.1.2
30
+ with:
31
+ github-token: ${{ secrets.GITHUB_TOKEN }}
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ inherit_gem:
2
+ rubocop-config-umbrellio: lib/rubocop.yml
3
+
4
+ AllCops:
5
+ DisplayCopNames: true
6
+ TargetRubyVersion: 2.7
7
+
8
+ Naming/FileName:
9
+ Exclude:
10
+ - lib/umbrellio-sequel-plugins.rb
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in sidekiq_web_google_auth.gemspec
6
+ gemspec
7
+
8
+ gem "rake"
data/Gemfile.lock ADDED
@@ -0,0 +1,141 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sidekiq_web_google_auth (0.1.0)
5
+ omniauth
6
+ omniauth-google-oauth2
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.1.3.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ ast (2.4.2)
18
+ concurrent-ruby (1.1.9)
19
+ connection_pool (2.2.5)
20
+ diff-lcs (1.5.0)
21
+ docile (1.4.0)
22
+ faraday (2.3.0)
23
+ faraday-net_http (~> 2.0)
24
+ ruby2_keywords (>= 0.0.4)
25
+ faraday-net_http (2.0.3)
26
+ hashie (5.0.0)
27
+ i18n (1.8.10)
28
+ concurrent-ruby (~> 1.0)
29
+ jwt (2.4.1)
30
+ minitest (5.14.4)
31
+ multi_json (1.15.0)
32
+ multi_xml (0.6.0)
33
+ oauth2 (1.4.9)
34
+ faraday (>= 0.17.3, < 3.0)
35
+ jwt (>= 1.0, < 3.0)
36
+ multi_json (~> 1.3)
37
+ multi_xml (~> 0.5)
38
+ rack (>= 1.2, < 3)
39
+ omniauth (2.1.0)
40
+ hashie (>= 3.4.6)
41
+ rack (>= 2.2.3)
42
+ rack-protection
43
+ omniauth-google-oauth2 (1.0.1)
44
+ jwt (>= 2.0)
45
+ oauth2 (~> 1.1)
46
+ omniauth (~> 2.0)
47
+ omniauth-oauth2 (~> 1.7.1)
48
+ omniauth-oauth2 (1.7.3)
49
+ oauth2 (>= 1.4, < 3)
50
+ omniauth (>= 1.9, < 3)
51
+ parallel (1.20.1)
52
+ parser (3.0.1.1)
53
+ ast (~> 2.4.1)
54
+ rack (2.2.3.1)
55
+ rack-protection (2.2.0)
56
+ rack
57
+ rack-test (1.1.0)
58
+ rack (>= 1.0, < 3)
59
+ rainbow (3.0.0)
60
+ rake (12.3.3)
61
+ redis (4.6.0)
62
+ regexp_parser (2.1.1)
63
+ rexml (3.2.5)
64
+ rspec (3.11.0)
65
+ rspec-core (~> 3.11.0)
66
+ rspec-expectations (~> 3.11.0)
67
+ rspec-mocks (~> 3.11.0)
68
+ rspec-core (3.11.0)
69
+ rspec-support (~> 3.11.0)
70
+ rspec-expectations (3.11.0)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.11.0)
73
+ rspec-mocks (3.11.1)
74
+ diff-lcs (>= 1.2.0, < 2.0)
75
+ rspec-support (~> 3.11.0)
76
+ rspec-support (3.11.0)
77
+ rubocop (1.11.0)
78
+ parallel (~> 1.10)
79
+ parser (>= 3.0.0.0)
80
+ rainbow (>= 2.2.2, < 4.0)
81
+ regexp_parser (>= 1.8, < 3.0)
82
+ rexml
83
+ rubocop-ast (>= 1.2.0, < 2.0)
84
+ ruby-progressbar (~> 1.7)
85
+ unicode-display_width (>= 1.4.0, < 3.0)
86
+ rubocop-ast (1.7.0)
87
+ parser (>= 3.0.1.1)
88
+ rubocop-config-umbrellio (1.11.0.51)
89
+ rubocop (= 1.11.0)
90
+ rubocop-performance (= 1.10.0)
91
+ rubocop-rails (= 2.9.1)
92
+ rubocop-rake (= 0.5.1)
93
+ rubocop-rspec (= 2.2.0)
94
+ rubocop-sequel (= 0.2.0)
95
+ rubocop-performance (1.10.0)
96
+ rubocop (>= 0.90.0, < 2.0)
97
+ rubocop-ast (>= 0.4.0)
98
+ rubocop-rails (2.9.1)
99
+ activesupport (>= 4.2.0)
100
+ rack (>= 1.1)
101
+ rubocop (>= 0.90.0, < 2.0)
102
+ rubocop-rake (0.5.1)
103
+ rubocop
104
+ rubocop-rspec (2.2.0)
105
+ rubocop (~> 1.0)
106
+ rubocop-ast (>= 1.1.0)
107
+ rubocop-sequel (0.2.0)
108
+ rubocop (~> 1.0)
109
+ ruby-progressbar (1.11.0)
110
+ ruby2_keywords (0.0.5)
111
+ sidekiq (6.5.1)
112
+ connection_pool (>= 2.2.2)
113
+ rack (~> 2.0)
114
+ redis (>= 4.2.0)
115
+ simplecov (0.21.2)
116
+ docile (~> 1.1)
117
+ simplecov-html (~> 0.11)
118
+ simplecov_json_formatter (~> 0.1)
119
+ simplecov-html (0.12.3)
120
+ simplecov-lcov (0.8.0)
121
+ simplecov_json_formatter (0.1.3)
122
+ tzinfo (2.0.4)
123
+ concurrent-ruby (~> 1.0)
124
+ unicode-display_width (2.0.0)
125
+ zeitwerk (2.4.2)
126
+
127
+ PLATFORMS
128
+ ruby
129
+
130
+ DEPENDENCIES
131
+ rack-test
132
+ rake
133
+ rspec
134
+ rubocop-config-umbrellio
135
+ sidekiq
136
+ sidekiq_web_google_auth!
137
+ simplecov
138
+ simplecov-lcov
139
+
140
+ BUNDLED WITH
141
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Igor Kir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # SidekiqWebGoogleAuth
2
+ [![Build Status](https://travis-ci.org/umbrellio/sidekiq_web_google_auth.svg?branch=master)](https://travis-ci.org/umbrellio/sidekiq_web_google_auth)
3
+ [![Coverage Status](https://coveralls.io/repos/github/umbrellio/sidekiq_web_google_auth/badge.svg?branch=master)](https://coveralls.io/github/umbrellio/sidekiq_web_google_auth?branch=master)
4
+ [![Gem Version](https://badge.fury.io/rb/sidekiq_web_google_auth.svg)](https://badge.fury.io/rb/sidekiq_web_google_auth)
5
+
6
+ Google OAuth for Sidekiq::Web
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'sidekiq_web_google_auth'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install sidekiq_web_google_auth
23
+
24
+ ## Usage
25
+
26
+ Initialize builder:
27
+
28
+ ```ruby
29
+ Sidekiq::Web.use(SidekiqWebGoogleAuth::Builder) do
30
+ provider(
31
+ "example_client_id", # Google OAuth client ID
32
+ "example_client_secret", # Google OAuth client secret
33
+ authorized_emails: %w[test@mail.com], # List of authorized emails
34
+ )
35
+ end
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/umbrellio/sidekiq_web_google_auth.
41
+
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46
+
47
+ ## Authors
48
+
49
+ Team Umbrellio
50
+
51
+ ---
52
+
53
+ <a href="https://github.com/umbrellio/">
54
+ <img style="float: left;" src="https://umbrellio.github.io/Umbrellio/supported_by_umbrellio.svg" alt="Supported by Umbrellio" width="439" height="72">
55
+ </a>
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sidekiq_web_google_auth"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "extension"
4
+
5
+ module SidekiqWebGoogleAuth
6
+ class Builder < OmniAuth::Builder
7
+ def provider(*args, authorized_emails:, **options, &block)
8
+ super("google_oauth2", *args, options.merge(name: "oauth"), &block)
9
+ Sidekiq::Web.register(SidekiqWebGoogleAuth::Extension.new(authorized_emails))
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Idea taken from https://github.com/mperham/sidekiq/issues/2460#issuecomment-125694743
4
+ module SidekiqWebGoogleAuth
5
+ class Extension
6
+ def initialize(authorized_emails)
7
+ @authorized_emails = authorized_emails
8
+ end
9
+
10
+ def registered(app) # rubocop:disable Metrics/MethodLength
11
+ authorized_emails = @authorized_emails
12
+
13
+ app.before do
14
+ if !session[:authenticated] && !request.path_info.start_with?("/auth")
15
+ redirect("#{root_path}auth/page")
16
+ end
17
+ end
18
+
19
+ app.get "/auth/page" do
20
+ "Please <a href='#{root_path}auth/oauth'>authenticate via Google</a>."
21
+ end
22
+
23
+ app.get "/auth/oauth/callback" do
24
+ auth = request.env["omniauth.auth"]
25
+
26
+ if auth && authorized_emails.include?(auth.info.email)
27
+ session[:authenticated] = true
28
+ redirect(root_path)
29
+ else
30
+ OmniAuth.logger.warn(
31
+ "Someone unauthorized is trying to gain access to Sidekiq: #{auth.info}",
32
+ )
33
+ redirect("#{root_path}auth/page")
34
+ end
35
+ end
36
+
37
+ app.get "/logout" do
38
+ session.clear
39
+ redirect(root_path)
40
+ end
41
+
42
+ app.tabs["Logout"] = "logout"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth"
4
+
5
+ OmniAuth.config.allowed_request_methods = [:get]
6
+ OmniAuth.config.silence_get_warning = true
7
+
8
+ module SidekiqWebGoogleAuth
9
+ require_relative "sidekiq_web_google_auth/builder"
10
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "sidekiq_web_google_auth"
5
+ spec.version = "0.1.0"
6
+ spec.authors = ["Igor Kir"]
7
+ spec.email = ["igor.kir@cadolabs.io"]
8
+
9
+ spec.summary = "Google OAuth for Sidekiq::Web"
10
+ spec.homepage = "https://github.com/umbrellio/sidekiq_web_google_auth"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/umbrellio/sidekiq_web_google_auth"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_runtime_dependency "omniauth"
27
+ spec.add_runtime_dependency "omniauth-google-oauth2"
28
+
29
+ spec.add_development_dependency "rack-test"
30
+ spec.add_development_dependency "rspec"
31
+ spec.add_development_dependency "rubocop-config-umbrellio"
32
+ spec.add_development_dependency "sidekiq"
33
+ spec.add_development_dependency "simplecov"
34
+ spec.add_development_dependency "simplecov-lcov"
35
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq_web_google_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Igor Kir
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-google-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-config-umbrellio
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sidekiq
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov-lcov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - igor.kir@cadolabs.io
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".github/workflows/ci.yml"
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".rubocop.yml"
136
+ - ".ruby-version"
137
+ - Gemfile
138
+ - Gemfile.lock
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - bin/console
143
+ - bin/setup
144
+ - lib/sidekiq_web_google_auth.rb
145
+ - lib/sidekiq_web_google_auth/builder.rb
146
+ - lib/sidekiq_web_google_auth/extension.rb
147
+ - sidekiq_web_google_auth.gemspec
148
+ homepage: https://github.com/umbrellio/sidekiq_web_google_auth
149
+ licenses:
150
+ - MIT
151
+ metadata:
152
+ homepage_uri: https://github.com/umbrellio/sidekiq_web_google_auth
153
+ source_code_uri: https://github.com/umbrellio/sidekiq_web_google_auth
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: 2.7.0
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubygems_version: 3.1.6
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Google OAuth for Sidekiq::Web
173
+ test_files: []