sidekiq_web_google_sign_in 1.0.0.beta1

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
+ SHA1:
3
+ metadata.gz: d90a0b01234663ee46221e6b3327bc26184afe4a
4
+ data.tar.gz: f16ca77b4141824ae96ada2e877eac2b270a7ab8
5
+ SHA512:
6
+ metadata.gz: ebd9b3623a6d15d04a79c6cb0080d69b3b8ec2be465dcaae897fa301da2f6f80add1e29a91f9d5852c6e2ca9ce066e6980fe262513d9a1a4e5fde0aa30cfe999
7
+ data.tar.gz: 2c2b4127575b74ff04651fe6c889386f6d9ea73b37d4ce11fabe68f48d34cccfd9d6bbd2ec6764fb11670b4760330eb0ed9fa82b5796a9ddf921fdae360e6d2b
@@ -0,0 +1,105 @@
1
+ require "omniauth-google-oauth2"
2
+
3
+ class SidekiqWebGoogleSignIn
4
+ class << self
5
+ attr_accessor :options
6
+
7
+ def use(options)
8
+ @options = options
9
+
10
+ # Require sidekiq web unless already required
11
+ unless defined?(Sidekiq::Web)
12
+ if defined?(Sidekiq::Enterprise)
13
+ require "sidekiq-ent/web"
14
+ elsif defined?(Sidekiq::Pro)
15
+ require "sidekiq/pro/web"
16
+ else
17
+ require "sidekiq/web"
18
+ end
19
+ end
20
+
21
+ google_sign_in_client_id, google_sign_in_client_secret = options.values_at(:google_sign_in_client_id, :google_sign_in_client_secret)
22
+ Sidekiq::Web.use OmniAuth::Builder do
23
+ provider :google_oauth2, google_sign_in_client_id, google_sign_in_client_secret
24
+ end
25
+ Sidekiq::Web.register(SidekiqWebGoogleSignIn)
26
+ Rails.application.config.after_initialize do
27
+ sidekiq_web_session_options = {
28
+ :key => "_sidekiqweb_session",
29
+ :domain => options[:session_domain],
30
+ :path => "/sidekiq",
31
+ :expire_after => 24 * 60 * 60, # Automatically expire session after 24 hours
32
+ :secret => session_secret
33
+ }
34
+ Sidekiq::Web.set :sessions, sidekiq_web_session_options
35
+ end
36
+ end
37
+
38
+ def registered(sidekiq_web)
39
+ sidekiq_web.before do
40
+ next if signing_in? or signed_in?
41
+
42
+ if html_request?
43
+ redirect_to_google_sign_in_page
44
+ else
45
+ halt(403)
46
+ end
47
+ end
48
+
49
+ sidekiq_web.get "/auth/google_oauth2/callback" do
50
+ if employee?
51
+ sign_in
52
+ redirect_to_sidekiq_dashboard
53
+ else
54
+ halt(403)
55
+ end
56
+ end
57
+
58
+ sidekiq_web.helpers do
59
+ def signed_in?
60
+ session[:signed_in]
61
+ end
62
+
63
+ def signing_in?
64
+ request.path_info.start_with?("/auth/google_oauth2")
65
+ end
66
+
67
+ def html_request?
68
+ request.env["HTTP_ACCEPT"].include?("text/html")
69
+ end
70
+
71
+ def redirect_to_google_sign_in_page
72
+ redirect "/sidekiq/auth/google_oauth2"
73
+ end
74
+
75
+ def employee?
76
+ is_employee_email?(request.env["omniauth.auth"]["info"]["email"])
77
+ end
78
+
79
+ def is_employee_email?(email)
80
+ SidekiqWebGoogleSignIn.options[:employee_emails].call(email)
81
+ end
82
+
83
+ def redirect_to_sidekiq_dashboard
84
+ redirect "/sidekiq"
85
+ end
86
+
87
+ def sign_in
88
+ session[:signed_in] = true
89
+ end
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ def session_secret
96
+ # Rails < 4
97
+ if Rails.configuration.respond_to?(:secret_token)
98
+ Rails.configuration.secret_token
99
+ # Rails >= 4
100
+ else
101
+ Rails.application.secrets[:secret_key_base]
102
+ end
103
+ end
104
+ end
105
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq_web_google_sign_in
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Nisanth Chunduru
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sidekiq
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.3
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
+ description: Restrict access to your Sidekiq using Google Sign In
42
+ email: nisanth074@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/sidekiq_web_google_sign_in.rb
48
+ homepage: https://github.com/magicbell-io/sidekiq_web_google_sign_in
49
+ licenses: []
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">"
63
+ - !ruby/object:Gem::Version
64
+ version: 1.3.1
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.4.5.1
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Restrict access to your Sidekiq using Google Sign In
71
+ test_files: []