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
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
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 |
# File 'lib/sidekiq_web_google_auth/extension.rb', line 17 def registered(app) 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 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 |