sidekiq_web_google_auth 0.2.5 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30eaf21bbeed7cf998f86ed5d42bfc9dda59d390cc3ca6b4c20af304be16ab3c
4
- data.tar.gz: caa945115d9790312abd19fed225434e8a21c918dfbce70a7f4bda0ca7c1fff9
3
+ metadata.gz: 338e2a345aedf3023bde02fa3169743497147bb30e93292823377cbcff949a06
4
+ data.tar.gz: ff7a6d37c164a171a81a8cde9a128b28d226058d6ed9fab7e6b897b7d76cb7e6
5
5
  SHA512:
6
- metadata.gz: 6f2d6d9bcf44052b966fe8684f6df0c679bedba846d25c7eea345f6da8878508f1f9b264f827845c8fe2bf0519904e0238e069e6cd75c89cda0dee14a176fde1
7
- data.tar.gz: 5fa33f207c8b5062b7c471df16478f7d4cba87d1b15e75b983cc55c355a838a748be7d7c8f738204cd89712def0caa427e5815aa6c5e1995b4d807ed86ba34e6
6
+ metadata.gz: 794d9d848099386a38363779efce2eed73a14e7c24017b3eed2c7b125cf7f5983e50563f423a739a303ade118754f87eee7f2a67d356c65225281d5bbb446828
7
+ data.tar.gz: 98105507c2e1c02e347ef17f64d782514338197b6d9b461593a17fd445df52e435aae35ebfc8711fa6467492183666658b33f4351ef5cff108e209566a866c2c
@@ -0,0 +1,67 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: write
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Extract version
17
+ id: version
18
+ run: |
19
+ version=$(grep -oP 'spec\.version\s*=\s*"\K[^"]+' sidekiq_web_google_auth.gemspec)
20
+ echo "tag=v$version" >> "$GITHUB_OUTPUT"
21
+
22
+ - name: Check if release already exists
23
+ id: check
24
+ run: |
25
+ if gh release view "${{ steps.version.outputs.tag }}" &>/dev/null; then
26
+ echo "exists=true" >> "$GITHUB_OUTPUT"
27
+ else
28
+ echo "exists=false" >> "$GITHUB_OUTPUT"
29
+ fi
30
+ env:
31
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32
+
33
+ - uses: ruby/setup-ruby@v1
34
+ if: steps.check.outputs.exists == 'false'
35
+ with:
36
+ ruby-version: "3.4"
37
+
38
+ - name: Build gem
39
+ if: steps.check.outputs.exists == 'false'
40
+ run: gem build sidekiq_web_google_auth.gemspec
41
+
42
+ - name: Check if version is already on RubyGems
43
+ id: rubygems
44
+ if: steps.check.outputs.exists == 'false'
45
+ run: |
46
+ version="${{ steps.version.outputs.tag }}"
47
+ status=$(curl -s -o /dev/null -w '%{http_code}' \
48
+ "https://rubygems.org/api/v2/rubygems/sidekiq_web_google_auth/versions/${version#v}.json")
49
+ if [ "$status" = "200" ]; then
50
+ echo "published=true" >> "$GITHUB_OUTPUT"
51
+ else
52
+ echo "published=false" >> "$GITHUB_OUTPUT"
53
+ fi
54
+
55
+ - name: Push gem to RubyGems
56
+ if: steps.check.outputs.exists == 'false' && steps.rubygems.outputs.published == 'false'
57
+ run: gem push *.gem
58
+ env:
59
+ GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
60
+
61
+ - uses: softprops/action-gh-release@v3
62
+ if: steps.check.outputs.exists == 'false'
63
+ with:
64
+ tag_name: ${{ steps.version.outputs.tag }}
65
+ target_commitish: ${{ github.sha }}
66
+ files: "*.gem"
67
+ generate_release_notes: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sidekiq_web_google_auth (0.2.5)
4
+ sidekiq_web_google_auth (0.3.1)
5
5
  omniauth
6
6
  omniauth-google-oauth2
7
7
  sidekiq (>= 8)
data/README.md CHANGED
@@ -29,12 +29,20 @@ Initialize builder:
29
29
  SidekiqWebGoogleAuth.setup!(
30
30
  client_id: "example_client_id", # Google OAuth client ID
31
31
  client_secret: "example_client_secret", # Google OAuth secret
32
- # You must provide at least one of: authorized_emails, authorized_email_domains
32
+ # You must provide at least one of: authorized_emails, authorized_emails_domains
33
33
  authorized_emails: %w[test@mail.com], # List of authorized emails
34
34
  authorized_emails_domains: %w[mail.com], # List of authorized emails domains
35
35
  )
36
36
  ```
37
37
 
38
+ Unauthenticated visitors go directly to Google. Only page loads are sent to Google; background requests from a signed-out tab, such as the dashboard's polling, get a `401` instead. By default, Google shows the account picker (`prompt: "select_account"`). If the selected account is denied, the access-denied page links back to Google so visitors can choose another account. Logging out lands on a signed-out page instead of redirecting straight back to Google. The links on the access-denied and signed-out pages always show the account picker, even with `prompt: nil`.
39
+
40
+ Pass additional `omniauth-google-oauth2` options as keywords to `setup!`. For example, add `hd: "example.com", prompt: "consent select_account"` to hint at a hosted domain and request both consent and account selection. Pass `prompt: nil` to omit the configured prompt and let Google use its default sign-in behavior. The provider name is always `oauth`, even if you pass `name:`.
41
+
42
+ ## Releasing
43
+
44
+ Bump `spec.version` in the gemspec, run `bundle install` so `Gemfile.lock` records the new version, and merge both to `master`. The Release workflow then pushes the gem to RubyGems and creates a GitHub release tagged `v<version>`; a version that already has a release is skipped, and a version already on RubyGems only gets its GitHub release.
45
+
38
46
  ## Contributing
39
47
 
40
48
  Bug reports and pull requests are welcome on GitHub at https://github.com/umbrellio/sidekiq_web_google_auth.
@@ -25,7 +25,21 @@ module SidekiqWebGoogleAuth
25
25
  end
26
26
 
27
27
  def deny(env)
28
- [302, { "location" => "#{env["SCRIPT_NAME"]}/auth/page" }, ["Found"]]
28
+ if navigation?(env)
29
+ [302, { "location" => "#{env["SCRIPT_NAME"]}/auth/oauth" }, ["Found"]]
30
+ else
31
+ [401, { "content-type" => "text/plain" }, ["Unauthorized"]]
32
+ end
33
+ end
34
+
35
+ # Background requests (e.g. dashboard polling) must not start a sign-in: it overwrites the
36
+ # OmniAuth state of a sign-in in progress.
37
+ def navigation?(env)
38
+ case env["HTTP_SEC_FETCH_MODE"]
39
+ when "navigate" then env.fetch("HTTP_SEC_FETCH_DEST", "document") == "document"
40
+ when nil then env["HTTP_ACCEPT"].to_s.include?("text/html")
41
+ else false
42
+ end
29
43
  end
30
44
 
31
45
  def session(env)
@@ -15,9 +15,7 @@ module SidekiqWebGoogleAuth
15
15
  end
16
16
 
17
17
  def registered(app)
18
- app.get "/auth/page" do
19
- "Please <a href='#{root_path}auth/oauth'>authenticate via Google</a>."
20
- end
18
+ register_sign_in_pages(app)
21
19
 
22
20
  app.get "/auth/oauth/callback" do
23
21
  auth = request.env["omniauth.auth"]
@@ -27,8 +25,9 @@ module SidekiqWebGoogleAuth
27
25
  session[:authenticated] = true
28
26
  redirect(root_path)
29
27
  else
28
+ details = auth&.info || "missing OAuth credentials"
30
29
  OmniAuth.logger.warn(
31
- "Someone unauthorized is trying to gain access to Sidekiq: #{auth.info}",
30
+ "Someone unauthorized is trying to gain access to Sidekiq: #{details}",
32
31
  )
33
32
  redirect("#{root_path}auth/page")
34
33
  end
@@ -36,7 +35,27 @@ module SidekiqWebGoogleAuth
36
35
 
37
36
  app.get "/logout" do
38
37
  session.clear
39
- redirect(root_path)
38
+ redirect("#{root_path}auth/signed_out")
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def register_sign_in_pages(app)
45
+ app.get "/auth/page" do
46
+ "Access denied. <a href='#{root_path}auth/oauth?prompt=select_account'>" \
47
+ "Sign in with another Google account</a>."
48
+ end
49
+
50
+ app.get "/auth/signed_out" do
51
+ "You have signed out. <a href='#{root_path}auth/oauth?prompt=select_account'>" \
52
+ "Sign in again</a>."
53
+ end
54
+
55
+ app.get "/auth/failure" do
56
+ message = request.params["message"].to_s
57
+ message = message.match?(/\A\w{1,64}\z/) ? " #{message}" : ""
58
+ "Google sign-in failed.#{message} <a href='#{root_path}auth/oauth'>Try again</a>."
40
59
  end
41
60
  end
42
61
  end
@@ -10,10 +10,15 @@ module SidekiqWebGoogleAuth
10
10
  require_relative "sidekiq_web_google_auth/builder"
11
11
  require_relative "sidekiq_web_google_auth/extension"
12
12
 
13
- def self.setup!(client_id:, client_secret:, authorized_emails:, authorized_emails_domains:)
13
+ def self.setup!(
14
+ client_id:, client_secret:, authorized_emails:, authorized_emails_domains:, **provider_options
15
+ )
16
+ options = { prompt: "select_account" }.merge(provider_options)
17
+ options[:name] = "oauth"
18
+
14
19
  Sidekiq::Web.configure do |config|
15
20
  config.use(OmniAuth::Builder) do
16
- provider(:google_oauth2, client_id, client_secret, name: "oauth")
21
+ provider(:google_oauth2, client_id, client_secret, **options)
17
22
  end
18
23
 
19
24
  SidekiqWebGoogleAuth::Extension.authorized_emails = authorized_emails
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sidekiq_web_google_auth"
5
- spec.version = "0.2.5"
5
+ spec.version = "0.3.1"
6
6
  spec.authors = ["Igor Kir"]
7
7
  spec.email = ["igor.kir@cadolabs.io"]
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_web_google_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kir
@@ -58,6 +58,7 @@ extensions: []
58
58
  extra_rdoc_files: []
59
59
  files:
60
60
  - ".github/workflows/ci.yml"
61
+ - ".github/workflows/release.yml"
61
62
  - ".gitignore"
62
63
  - ".rspec"
63
64
  - ".rubocop.yml"
@@ -93,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
94
  - !ruby/object:Gem::Version
94
95
  version: '0'
95
96
  requirements: []
96
- rubygems_version: 3.6.7
97
+ rubygems_version: 3.6.9
97
98
  specification_version: 4
98
99
  summary: Google OAuth for Sidekiq::Web
99
100
  test_files: []