Class: Clowk::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/clowk/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/clowk/configuration.rb', line 30

def initialize
  @api_base_url = "https://api.clowk.dev/api/v1"
  @app_base_url = "https://app.clowk.in"
  @after_sign_in_path = "/"
  @after_sign_out_path = "/"
  @mount_path = "/clowk"
  @callback_path = "/clowk/oauth/callback"
  @cookie_key = "clowk_token"
  @http_logger = nil
  @http_open_timeout = 5
  @http_read_timeout = 10
  @http_retry_attempts = 2
  @http_retry_interval = 0.05
  @http_write_timeout = 10
  @issuer = "clowk"
  @session_key = :clowk
  @prefix_by = :clowk
  @token_param = :token
  @enforce_active_session = false
  @on_session_expired = nil
  # How long a fetched session status stays trusted, in seconds. Without a
  # TTL the first lookup would be cached for the life of the Rails session,
  # which silently turns every later enforcement call into a no-op. Set 0 to
  # check on every call.
  @session_status_ttl = 300
end

Instance Attribute Details

#after_sign_in_pathObject



73
74
75
# File 'lib/clowk/configuration.rb', line 73

def 
  resolve_path(@after_sign_in_path)
end

#after_sign_out_pathObject



77
78
79
# File 'lib/clowk/configuration.rb', line 77

def after_sign_out_path
  resolve_path(@after_sign_out_path)
end

#api_base_urlObject

Returns the value of attribute api_base_url.



5
6
7
# File 'lib/clowk/configuration.rb', line 5

def api_base_url
  @api_base_url
end

#app_base_urlObject

Returns the value of attribute app_base_url.



6
7
8
# File 'lib/clowk/configuration.rb', line 6

def app_base_url
  @app_base_url
end

#audienceObject

Defaults to the publishable key, which is what Clowk stamps into aud. Consumers already configure that key, so audience checking is on by default rather than something you have to know to switch on.



69
70
71
# File 'lib/clowk/configuration.rb', line 69

def audience
  @audience.nil? ? @publishable_key : @audience
end

#callback_pathObject

Returns the value of attribute callback_path.



7
8
9
# File 'lib/clowk/configuration.rb', line 7

def callback_path
  @callback_path
end

Returns the value of attribute cookie_key.



8
9
10
# File 'lib/clowk/configuration.rb', line 8

def cookie_key
  @cookie_key
end

#enforce_active_sessionObject

Returns the value of attribute enforce_active_session.



25
26
27
# File 'lib/clowk/configuration.rb', line 25

def enforce_active_session
  @enforce_active_session
end

#http_loggerObject

Returns the value of attribute http_logger.



9
10
11
# File 'lib/clowk/configuration.rb', line 9

def http_logger
  @http_logger
end

#http_open_timeoutObject

Returns the value of attribute http_open_timeout.



10
11
12
# File 'lib/clowk/configuration.rb', line 10

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutObject

Returns the value of attribute http_read_timeout.



11
12
13
# File 'lib/clowk/configuration.rb', line 11

def http_read_timeout
  @http_read_timeout
end

#http_retry_attemptsObject

Returns the value of attribute http_retry_attempts.



12
13
14
# File 'lib/clowk/configuration.rb', line 12

def http_retry_attempts
  @http_retry_attempts
end

#http_retry_intervalObject

Returns the value of attribute http_retry_interval.



13
14
15
# File 'lib/clowk/configuration.rb', line 13

def http_retry_interval
  @http_retry_interval
end

#http_write_timeoutObject

Returns the value of attribute http_write_timeout.



14
15
16
# File 'lib/clowk/configuration.rb', line 14

def http_write_timeout
  @http_write_timeout
end

#issuerObject

Returns the value of attribute issuer.



16
17
18
# File 'lib/clowk/configuration.rb', line 16

def issuer
  @issuer
end

#jwks_urlObject

Returns the value of attribute jwks_url.



17
18
19
# File 'lib/clowk/configuration.rb', line 17

def jwks_url
  @jwks_url
end

#mount_pathObject

Returns the value of attribute mount_path.



18
19
20
# File 'lib/clowk/configuration.rb', line 18

def mount_path
  @mount_path
end

#on_session_expiredObject

Returns the value of attribute on_session_expired.



26
27
28
# File 'lib/clowk/configuration.rb', line 26

def on_session_expired
  @on_session_expired
end

#prefix_byObject

Returns the value of attribute prefix_by.



20
21
22
# File 'lib/clowk/configuration.rb', line 20

def prefix_by
  @prefix_by
end

#publishable_keyObject

Returns the value of attribute publishable_key.



19
20
21
# File 'lib/clowk/configuration.rb', line 19

def publishable_key
  @publishable_key
end

#secret_keyObject

Returns the value of attribute secret_key.



21
22
23
# File 'lib/clowk/configuration.rb', line 21

def secret_key
  @secret_key
end

#session_keyObject

Returns the value of attribute session_key.



22
23
24
# File 'lib/clowk/configuration.rb', line 22

def session_key
  @session_key
end

#session_status_cacheObject

Where API-only apps cache session status, since they have no Rails session to hang it on. Defaults to Rails.cache when Rails is loaded; set to nil to check with Clowk on every authenticated request.



60
61
62
63
64
# File 'lib/clowk/configuration.rb', line 60

def session_status_cache
  return @session_status_cache if defined?(@session_status_cache)

  @session_status_cache = (defined?(::Rails) && ::Rails.respond_to?(:cache)) ? ::Rails.cache : nil
end

#session_status_ttlObject

Returns the value of attribute session_status_ttl.



27
28
29
# File 'lib/clowk/configuration.rb', line 27

def session_status_ttl
  @session_status_ttl
end

#subdomain_urlObject

Returns the value of attribute subdomain_url.



23
24
25
# File 'lib/clowk/configuration.rb', line 23

def subdomain_url
  @subdomain_url
end

#token_paramObject

Returns the value of attribute token_param.



24
25
26
# File 'lib/clowk/configuration.rb', line 24

def token_param
  @token_param
end

Instance Method Details

#validate!Object

Raises:



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/clowk/configuration.rb', line 85

def validate!
  errors = []
  errors << "secret_key must be a String" unless @secret_key.is_a?(String) || @secret_key.nil?
  errors << "http_open_timeout must be Numeric" unless @http_open_timeout.is_a?(Numeric)
  errors << "http_read_timeout must be Numeric" unless @http_read_timeout.is_a?(Numeric)
  errors << "http_write_timeout must be Numeric" unless @http_write_timeout.is_a?(Numeric)
  errors << "http_retry_attempts must be a non-negative Integer" unless @http_retry_attempts.is_a?(Integer) && @http_retry_attempts >= 0
  errors << "session_status_ttl must be a non-negative Integer" unless @session_status_ttl.is_a?(Integer) && @session_status_ttl >= 0

  raise ConfigurationError, errors.join(", ") if errors.any?

  true
end