Class: Angus::Authentication::Client

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

Constant Summary collapse

AUTHENTICATION_HEADER =
'AUTHORIZATION'
BAAS_AUTHENTICATION_HEADER =
'X-BAAS-AUTH'
BAAS_SESSION_HEADER =
'X-Baas-Session-Seed'
DATE_HEADER =
'DATE'

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/angus/authentication/client.rb', line 14

def initialize(settings)
  unless settings[:public_key] && settings[:private_key]
    warn "No authentication info provided, angus-authentication has been disabled for: #{settings[:service_id]}"
    @enabled = false
    return
  end

  @enabled = true
  @public_key = settings[:public_key]
  @private_key = settings[:private_key]

  @store = RedisClient.new(settings[:store] || {})
end

Instance Method Details

#prepare_request(request, http_method, script_name) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/angus/authentication/client.rb', line 28

def prepare_request(request, http_method, script_name)
  return unless @enabled

  date = Date.today

  auth_token = generate_auth_token(date, http_method, script_name)
  request[DATE_HEADER] = date.httpdate
  request[AUTHENTICATION_HEADER] = generate_auth_header(auth_token)

  session_auth_token = generate_session_auth_token(date, http_method, script_name)
  request[BAAS_AUTHENTICATION_HEADER] = generate_auth_header(session_auth_token)
end

#store_session_private_key(response) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/angus/authentication/client.rb', line 41

def store_session_private_key(response)
  return unless @enabled

  session_key_seed = extract_session_key_seed(response)
  return unless session_key_seed

  session_key = generate_session_private(session_key_seed)

  @store.store_session_key(@public_key, session_key)
end