Class: KeycloakApiRails::Configuration

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

Constant Summary collapse

LOGGER_METHODS =
[:debug, :info, :warn, :error].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#allow_token_in_query_stringObject

Returns the value of attribute allow_token_in_query_string.



19
20
21
# File 'lib/keycloak-api-rails/configuration.rb', line 19

def allow_token_in_query_string
  @allow_token_in_query_string
end

#ca_certificate_fileObject

Returns the value of attribute ca_certificate_file.



15
16
17
# File 'lib/keycloak-api-rails/configuration.rb', line 15

def ca_certificate_file
  @ca_certificate_file
end

#custom_attributesObject

Returns the value of attribute custom_attributes.



13
14
15
# File 'lib/keycloak-api-rails/configuration.rb', line 13

def custom_attributes
  @custom_attributes
end

#expected_audienceObject

Returns the value of attribute expected_audience.



16
17
18
# File 'lib/keycloak-api-rails/configuration.rb', line 16

def expected_audience
  @expected_audience
end

#expected_token_typeObject

Returns the value of attribute expected_token_type.



17
18
19
# File 'lib/keycloak-api-rails/configuration.rb', line 17

def expected_token_type
  @expected_token_type
end

#http_open_timeoutObject

Returns the value of attribute http_open_timeout.



20
21
22
# File 'lib/keycloak-api-rails/configuration.rb', line 20

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutObject

Returns the value of attribute http_read_timeout.



21
22
23
# File 'lib/keycloak-api-rails/configuration.rb', line 21

def http_read_timeout
  @http_read_timeout
end

#loggerObject

Returns the value of attribute logger.



14
15
16
# File 'lib/keycloak-api-rails/configuration.rb', line 14

def logger
  @logger
end

#opt_inObject

Returns the value of attribute opt_in.



10
11
12
# File 'lib/keycloak-api-rails/configuration.rb', line 10

def opt_in
  @opt_in
end

#public_key_cache_ttlObject

Returns the value of attribute public_key_cache_ttl.



12
13
14
# File 'lib/keycloak-api-rails/configuration.rb', line 12

def public_key_cache_ttl
  @public_key_cache_ttl
end

#realm_idObject

Returns the value of attribute realm_id.



8
9
10
# File 'lib/keycloak-api-rails/configuration.rb', line 8

def realm_id
  @realm_id
end

#server_urlObject

Returns the value of attribute server_url.



7
8
9
# File 'lib/keycloak-api-rails/configuration.rb', line 7

def server_url
  @server_url
end

#skip_pathsObject

Returns the value of attribute skip_paths.



9
10
11
# File 'lib/keycloak-api-rails/configuration.rb', line 9

def skip_paths
  @skip_paths
end

#token_expiration_tolerance_in_secondsObject

Returns the value of attribute token_expiration_tolerance_in_seconds.



11
12
13
# File 'lib/keycloak-api-rails/configuration.rb', line 11

def token_expiration_tolerance_in_seconds
  @token_expiration_tolerance_in_seconds
end

#verify_not_beforeObject

Returns the value of attribute verify_not_before.



18
19
20
# File 'lib/keycloak-api-rails/configuration.rb', line 18

def verify_not_before
  @verify_not_before
end

Instance Method Details

#server_configured?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/keycloak-api-rails/configuration.rb', line 58

def server_configured?
  !missing?(server_url) && !missing?(realm_id)
end

#validate!Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/keycloak-api-rails/configuration.rb', line 23

def validate!
  errors = []

  errors.push("'server_url' must be a String or nil, got #{server_url.inspect}") unless server_url.nil? || server_url.is_a?(String)
  errors.push("'realm_id' must be a String or nil, got #{realm_id.inspect}") unless realm_id.nil? || realm_id.is_a?(String)
  errors.push("'logger' must respond to #{LOGGER_METHODS.join(', ')}") unless LOGGER_METHODS.all? { |method| logger.respond_to?(method) }
  errors.push("'opt_in' must be true or false, got #{opt_in.inspect}") unless boolean?(opt_in)
  errors.push("'verify_not_before' must be true or false, got #{verify_not_before.inspect}") unless boolean?(verify_not_before)
  errors.push("'allow_token_in_query_string' must be true or false, got #{allow_token_in_query_string.inspect}") unless boolean?(allow_token_in_query_string)
  errors.push("'custom_attributes' must be an Array of claim names, got #{custom_attributes.inspect}") unless custom_attributes.is_a?(Array)
  errors.push("'token_expiration_tolerance_in_seconds' must be a number of seconds, got #{token_expiration_tolerance_in_seconds.inspect}") unless number?(token_expiration_tolerance_in_seconds, allow_zero: true)
  errors.push("'public_key_cache_ttl' must be a positive number of seconds, got #{public_key_cache_ttl.inspect}") unless number?(public_key_cache_ttl)
  errors.push("'http_open_timeout' must be a positive number of seconds, got #{http_open_timeout.inspect}") unless number?(http_open_timeout)
  errors.push("'http_read_timeout' must be a positive number of seconds, got #{http_read_timeout.inspect}") unless number?(http_read_timeout)
  errors.push("'expected_token_type' must be a String or nil, got #{expected_token_type.inspect}") unless expected_token_type.nil? || expected_token_type.is_a?(String)
  errors.push("'ca_certificate_file' must be the path of a readable file, got #{ca_certificate_file.inspect}") unless ca_certificate_file.nil? || File.readable?(ca_certificate_file.to_s)

  errors.concat(skip_paths_errors)
  errors.concat(expected_audience_errors)

  raise InvalidConfigurationError, "Invalid Keycloak configuration: #{errors.join('; ')}" unless errors.empty?

  true
end

#validate_server!Object



48
49
50
51
52
53
54
55
56
# File 'lib/keycloak-api-rails/configuration.rb', line 48

def validate_server!
  errors = []
  errors.push("'server_url' must be configured, e.g. 'https://keycloak.example.org'") if missing?(server_url)
  errors.push("'realm_id' must be configured, e.g. 'master'") if missing?(realm_id)

  raise InvalidConfigurationError, "Invalid Keycloak configuration: #{errors.join('; ')}" unless errors.empty?

  true
end