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!!'
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.



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

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
  @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



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

def authenticate!
  return unless should_authenticate?

  if has_session?
    authenticate_session
  else
    start_session
  end
end

#update_response_header(response) ⇒ Object



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

def update_response_header(response)
  return unless should_authenticate?

  headers = response[1]

  session_data = @store.get_session_data(session_id)

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