Module: PhraseApp::Auth

Defined in:
lib/auth.rb

Defined Under Namespace

Classes: AuthHandler

Class Method Summary collapse

Class Method Details

.authenticate(req) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/auth.rb', line 48

def self.authenticate(req)
  if authH == nil
    raise("no auth handler registered")
  end

  if err = authH.load_config
    return err
  end

  if err = authH.validate
    return err
  end

  if authH.token && authH.token != ""
    req["Authorization"] = "token #{authH.token}"
  elsif authH.username && authH.username != ""
    req.basic_auth(authH.username, authH.password)

    if authH.tfa or authH.tfa_token # TFA only required for username+password based login.
      raise "Multi-Factor Token required in config but not provided." unless authH.tfa_token
      req["X-PhraseApp-OTP"] = auth.tfa_token
    end
  else
    raise "No authentication present"
  end

  return nil

end

.authHObject



40
41
42
# File 'lib/auth.rb', line 40

def self.authH
  defined?(@@authH) && @@authH
end

.register_auth_handler(a) ⇒ Object



44
45
46
# File 'lib/auth.rb', line 44

def self.register_auth_handler(a)
  @@authH = a
end