Class: Angus::Authentication::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/angus/authentication/provider.rb

Constant Summary collapse

DEFAULT_ID_TTL =
60 * 60
DEFAULT_SESSION_TTL =
60 * 60
DEFAULT_PRIVATE_KEY =
'change_me'
DEFAULT_USE_SESSION =
false
AUTHENTICATION_HEADER =
'HTTP_AUTHORIZATION'
BAAS_AUTHENTICATION_HEADER =
'HTTP_X_BAAS_AUTH'
BAAS_SESSION_HEADER =
'X-Baas-Session-Seed'
DATE_HEADER =
'HTTP_DATE'
REQUEST_HEADER =
'REQUEST_METHOD'
PATH_HEADER =
'PATH_INFO'

Instance Method Summary collapse

Constructor Details

#initialize(settings, env) ⇒ Provider

Returns a new instance of Provider.



24
25
26
27
28
29
30
31
32
33
# File 'lib/angus/authentication/provider.rb', line 24

def initialize(settings, env)
  @session_id_ttl = settings[:session_id_ttl] || DEFAULT_ID_TTL
  @session_ttl = settings[:session_ttl] || DEFAULT_SESSION_TTL
  @private_key = settings[:private_key] || DEFAULT_PRIVATE_KEY
  @use_session = settings[:use_session]
  @authenticator = settings[:authenticator] || DefaultAuthenticator.new(@private_key)
  @store = RedisStore.new(settings[:store] || {})
  @excluded_regexps = settings[:excluded_regexps] || []
  @env = env
end

Instance Method Details

#authenticate!Object



35
36
37
38
39
40
41
42
43
# File 'lib/angus/authentication/provider.rb', line 35

def authenticate!
  return unless should_authenticate?

  if has_session? && use_session?
    authenticate_session
  else
    start_session
  end
end

#update_response_header(response) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/angus/authentication/provider.rb', line 45

def update_response_header(response)
  return unless use_session? && should_authenticate?

  headers = response[1]

  headers[BAAS_SESSION_HEADER] = get_session_data['key_seed']
end