Class: Mumukit::Login::Provider::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mumukit/login/provider/base.rb

Direct Known Subclasses

Auth0, Cas, Developer, Google, Saml

Instance Method Summary collapse

Instance Method Details

#auth_pathObject



24
25
26
# File 'lib/mumukit/login/provider/base.rb', line 24

def auth_path
  "/auth/#{name}"
end

#button_html(controller, title, clazz) ⇒ Object



36
37
38
# File 'lib/mumukit/login/provider/base.rb', line 36

def button_html(controller, title, clazz)
  %Q{<a class="#{clazz}" href="#{login_path(controller)}">#{title}</a>}
end

#callback_pathObject



28
29
30
# File 'lib/mumukit/login/provider/base.rb', line 28

def callback_path
  "/auth/#{name}/callback"
end

#computed_settings(effective_settings) ⇒ Object

Provider settings that are computed based on effective settings - that is, the default settings merged with the organizations settings.

Override this method in order to provide settings that depend not only on the organization or defaults, but also commputed expressions.

These settings can not be overriden.



77
78
79
# File 'lib/mumukit/login/provider/base.rb', line 77

def computed_settings(effective_settings)
  {}
end

#default_settingsObject

Default provider settings that come from the environment

Override this method in order to read ENV and in order to provide default settings

These setting can be overriden by organization’s ‘provider_settings` and by the provider’s ‘computed_settings`



66
67
68
# File 'lib/mumukit/login/provider/base.rb', line 66

def default_settings
  {}
end

#destroy_session!(_controller) ⇒ Object



48
49
# File 'lib/mumukit/login/provider/base.rb', line 48

def destroy_session!(_controller)
end

#finalize_user_creation!(_user) ⇒ Object



81
82
# File 'lib/mumukit/login/provider/base.rb', line 81

def finalize_user_creation!(_user)
end


40
41
42
# File 'lib/mumukit/login/provider/base.rb', line 40

def footer_html(*)
  nil
end

#header_htmlObject



44
45
46
# File 'lib/mumukit/login/provider/base.rb', line 44

def header_html(*)
  nil
end

#login_path(controller) ⇒ Object



13
14
15
# File 'lib/mumukit/login/provider/base.rb', line 13

def (controller)
  create_uri '/login', (controller)
end

#login_path_params(controller) ⇒ Object



17
18
19
20
21
22
# File 'lib/mumukit/login/provider/base.rb', line 17

def (controller)
  {
      origin: create_uri(controller.request.path, controller.request.params),
      organization: Mumukit::Platform::Organization.current.name
  }
end

#logout_redirection_pathObject



32
33
34
# File 'lib/mumukit/login/provider/base.rb', line 32

def logout_redirection_path
  '/'
end

#nameObject



3
4
5
# File 'lib/mumukit/login/provider/base.rb', line 3

def name
  @name ||= self.class.name.demodulize.downcase
end

#request_authentication!(controller, _login_settings) ⇒ Object



9
10
11
# File 'lib/mumukit/login/provider/base.rb', line 9

def request_authentication!(controller, )
  controller.redirect! auth_path
end

#setup_procObject



51
52
53
54
55
56
57
58
# File 'lib/mumukit/login/provider/base.rb', line 51

def setup_proc
  proc do |env|
    options = env['omniauth.strategy'].options
    effective_settings = default_settings.to_h.merge((env))
    options.merge!(effective_settings)
    options.merge!(computed_settings(effective_settings.to_struct))
  end
end

#uid_for_profile(omniauth) ⇒ Object



84
85
86
# File 'lib/mumukit/login/provider/base.rb', line 84

def uid_for_profile(omniauth)
  omniauth.info.email || omniauth.uid
end