Class: SecondFactor::Actions::DiscourseConnectProvider

Inherits:
Base
  • Object
show all
Defined in:
lib/second_factor/actions/discourse_connect_provider.rb

Instance Attribute Summary

Attributes inherited from Base

#current_user, #guardian, #request

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SecondFactor::Actions::Base

Instance Method Details

#no_second_factors_enabled!(params) ⇒ Object



34
35
36
37
38
39
# File 'lib/second_factor/actions/discourse_connect_provider.rb', line 34

def no_second_factors_enabled!(params)
  sso = get_sso(payload(params))
  populate_user_data(sso)
  sso.no_2fa_methods = true
  { sso_redirect_url: sso.to_url(sso.return_sso_url) }
end

#second_factor_auth_completed!(callback_params) ⇒ Object



59
60
61
62
63
64
# File 'lib/second_factor/actions/discourse_connect_provider.rb', line 59

def second_factor_auth_completed!(callback_params)
  sso = get_sso(callback_params[:payload])
  populate_user_data(sso)
  sso.confirmed_2fa = true
  { sso_redirect_url: sso.to_url(sso.return_sso_url) }
end

#second_factor_auth_required!(params) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/second_factor/actions/discourse_connect_provider.rb', line 41

def second_factor_auth_required!(params)
  pl = payload(params)
  sso = get_sso(pl)
  hostname = URI(sso.return_sso_url).hostname
  {
    callback_params: {
      payload: pl,
    },
    callback_path: session_sso_provider_path,
    callback_method: "GET",
    description:
      I18n.t(
        "second_factor_auth.actions.discourse_connect_provider.description",
        hostname: hostname,
      ),
  }
end

#second_factor_auth_skipped!(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/second_factor/actions/discourse_connect_provider.rb', line 10

def second_factor_auth_skipped!(params)
  sso = get_sso(payload(params))
  return { logout: true, return_sso_url: sso.return_sso_url } if sso.logout
  if !current_user
    if sso.prompt == "none"
      # 'prompt=none' was requested, so just return a failed authentication
      # without putting up a login dialog and interrogating the user.
      sso.failed = true
      return(
        {
          no_current_user: true,
          prompt: sso.prompt,
          sso_redirect_url: sso.to_url(sso.return_sso_url),
        }
      )
    end
    # ...otherwise, trigger the usual redirect to login dialog.
    return { no_current_user: true }
  end
  populate_user_data(sso)
  sso.confirmed_2fa = true if @opts[:confirmed_2fa_during_login]
  { sso_redirect_url: sso.to_url(sso.return_sso_url) }
end

#skip_second_factor_auth?(params) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
# File 'lib/second_factor/actions/discourse_connect_provider.rb', line 5

def skip_second_factor_auth?(params)
  sso = get_sso(payload(params))
  !current_user || sso.logout || !sso.require_2fa || @opts[:confirmed_2fa_during_login]
end