Class: Wsaa::Client

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

Overview

WSAA authentication client.

Orchestrates the authentication flow: builds TRA, signs it, calls WSAA, and caches credentials.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Client

Creates a new Client.

Parameters:



18
19
20
# File 'lib/wsaa/client.rb', line 18

def initialize(configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationConfiguration (readonly)

The client configuration.

Returns:



11
12
13
# File 'lib/wsaa/client.rb', line 11

def configuration
  @configuration
end

Instance Method Details

#authenticateCredentials

Authenticates with WSAA using cached credentials if available.

Returns:

Raises:



28
29
30
31
32
33
34
35
# File 'lib/wsaa/client.rb', line 28

def authenticate
  configuration.validate!

  cached = credential_store.read
  return cached if cached

  authenticate!
end

#authenticate!Credentials

Authenticates with WSAA, ignoring any cached credentials.

Returns:

Raises:



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/wsaa/client.rb', line 43

def authenticate!
  configuration.validate!

  tra = build_tra
  signed_tra = sign_tra(tra.to_xml)
  response = call_wsaa(signed_tra)
  credentials = parse_response(response, tra.expiration_time)

  credential_store.write(credentials)
  credentials
end