Class: SidekiqWebGoogleAuth::Extension
- Inherits:
-
Object
- Object
- SidekiqWebGoogleAuth::Extension
- Defined in:
- lib/sidekiq_web_google_auth/extension.rb
Class Attribute Summary collapse
-
.authorized_emails ⇒ Object
Returns the value of attribute authorized_emails.
-
.authorized_emails_domains ⇒ Object
Returns the value of attribute authorized_emails_domains.
Class Method Summary collapse
-
.registered(app) ⇒ Object
rubocop:disable Metrics/MethodLength.
- .valid_email?(email) ⇒ Boolean
- .valid_email_domain?(email) ⇒ Boolean
Class Attribute Details
.authorized_emails ⇒ Object
Returns the value of attribute authorized_emails.
7 8 9 |
# File 'lib/sidekiq_web_google_auth/extension.rb', line 7 def @authorized_emails end |
.authorized_emails_domains ⇒ Object
Returns the value of attribute authorized_emails_domains.
7 8 9 |
# File 'lib/sidekiq_web_google_auth/extension.rb', line 7 def @authorized_emails_domains end |
Class Method Details
.registered(app) ⇒ Object
rubocop:disable Metrics/MethodLength
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sidekiq_web_google_auth/extension.rb', line 17 def registered(app) # rubocop:disable Metrics/MethodLength app.before do if !session[:authenticated] && !request.path_info.start_with?("/auth") redirect("#{root_path}auth/page") end end app.get "/auth/page" do "Please <a href='#{root_path}auth/oauth'>authenticate via Google</a>." end app.get "/auth/oauth/callback" do auth = request.env["omniauth.auth"] ext = SidekiqWebGoogleAuth::Extension if auth && ext.valid_email?(auth.info.email) && ext.valid_email_domain?(auth.info.email) session[:authenticated] = true redirect(root_path) else OmniAuth.logger.warn( "Someone unauthorized is trying to gain access to Sidekiq: #{auth.info}", ) redirect("#{root_path}auth/page") end end app.get "/logout" do session.clear redirect(root_path) end app.tabs["Logout"] = "logout" end |
.valid_email?(email) ⇒ Boolean
9 10 11 |
# File 'lib/sidekiq_web_google_auth/extension.rb', line 9 def valid_email?(email) .empty? || .include?(email) end |
.valid_email_domain?(email) ⇒ Boolean
13 14 15 |
# File 'lib/sidekiq_web_google_auth/extension.rb', line 13 def valid_email_domain?(email) .empty? || .include?(email[/(?<=@).+/]) end |