Class: KeycloakAdmin::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/keycloak-admin/configuration.rb

Constant Summary collapse

TOKEN_EXPIRY_SAFETY_MARGIN_SECONDS =

Treat a cached token as expired this many seconds before its real expiry, so it cannot go stale between the check below and the request that relies on it.

10

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



5
6
7
# File 'lib/keycloak-admin/configuration.rb', line 5

def client_id
  @client_id
end

#client_realm_nameObject

Returns the value of attribute client_realm_name.



5
6
7
# File 'lib/keycloak-admin/configuration.rb', line 5

def client_realm_name
  @client_realm_name
end

#client_secretObject

Returns the value of attribute client_secret.



5
6
7
# File 'lib/keycloak-admin/configuration.rb', line 5

def client_secret
  @client_secret
end

#faraday_optionsObject

Returns the value of attribute faraday_options.



5
6
7
# File 'lib/keycloak-admin/configuration.rb', line 5

def faraday_options
  @faraday_options
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/keycloak-admin/configuration.rb', line 5

def logger
  @logger
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/keycloak-admin/configuration.rb', line 5

def password
  @password
end

#server_domainObject

Returns the value of attribute server_domain.



5
6
7
# File 'lib/keycloak-admin/configuration.rb', line 5

def server_domain
  @server_domain
end

#server_urlObject

Returns the value of attribute server_url.



5
6
7
# File 'lib/keycloak-admin/configuration.rb', line 5

def server_url
  @server_url
end

#use_service_accountObject

Returns the value of attribute use_service_account.



5
6
7
# File 'lib/keycloak-admin/configuration.rb', line 5

def 
  @use_service_account
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/keycloak-admin/configuration.rb', line 5

def username
  @username
end

Instance Method Details

#body_for_token_retrievalObject



29
30
31
32
33
34
35
# File 'lib/keycloak-admin/configuration.rb', line 29

def body_for_token_retrieval
  if 
    
  else
    body_for_username_and_password
  end
end

#cache_token(token_representation) ⇒ Object



17
18
19
20
21
22
# File 'lib/keycloak-admin/configuration.rb', line 17

def cache_token(token_representation)
  return token_representation unless token_representation.expires_in.is_a?(Numeric)
  @cached_token     = token_representation
  @token_expires_at = Time.now + token_representation.expires_in - TOKEN_EXPIRY_SAFETY_MARGIN_SECONDS
  token_representation
end

#cached_tokenObject

Returns the cached TokenRepresentation, or nil if there is none or it is (about to be) expired.



12
13
14
15
# File 'lib/keycloak-admin/configuration.rb', line 12

def cached_token
  return nil if @token_expires_at.nil? || Time.now >= @token_expires_at
  @cached_token
end

#clear_cached_token!Object



24
25
26
27
# File 'lib/keycloak-admin/configuration.rb', line 24

def clear_cached_token!
  @cached_token     = nil
  @token_expires_at = nil
end

#headers_for_token_retrievalObject



37
38
39
40
41
42
43
# File 'lib/keycloak-admin/configuration.rb', line 37

def headers_for_token_retrieval
  if 
    
  else
    headers_for_username_and_password
  end
end