authbox 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/authbox.rb +31 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acc525e74ec5937d46906f9e1f682638c7dbce9c
4
- data.tar.gz: cebb588c2567adb44f391d54314dc416be283d77
3
+ metadata.gz: 88f3bad31b1a1dc5767a54eba3593de501f0a0bb
4
+ data.tar.gz: d3f8f8c13f83a669824f9f3488915c1a95cb49ef
5
5
  SHA512:
6
- metadata.gz: 37e6bd3aa6c75788b93eb0a2ae44b1ce1fbe37938a610c46b54a5b7716d35c6b8301541fa343794bad2d60efba3ae2e6662d54ed93e0ee813350b0f465027f56
7
- data.tar.gz: a8f53a2318c8a7b6311fb9a8d0f6286e20461430db3205cdb7b37fe16c5071170a827aba1b9991cae61f9d4973a137c79acd4f6ee7cfd88e42a65a8810a408bd
6
+ metadata.gz: c52b50856e96ebcf07272763549b82432613b69aa7abc1fd009c8ad57de51686e07ae1f89f00ac1a8acf513f0d59516905248fb89d5dc0b844580a8930288821
7
+ data.tar.gz: 04823d5d38976a4a89debf7f7e5bad4c4ef55657320e90eea2dc82da6b05143c606852f599ef509adde7c4ac7c8d465623bb5780a2bf30cf796c77fcadb52fd1
data/lib/authbox.rb CHANGED
@@ -85,6 +85,8 @@ module Authbox
85
85
  ##
86
86
  # Override me to inject a custom HTTP POST library
87
87
  def authbox_post_form(uri, body)
88
+ authbox_debug_log {"Posting data to #{uri}: #{body}"}
89
+
88
90
  req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
89
91
  req.body = body.to_json
90
92
 
@@ -92,7 +94,7 @@ module Authbox
92
94
  begin
93
95
  http.request(req)
94
96
  rescue => e
95
- logger.warn 'AUTHBOX: HTTP request error: #{e}'
97
+ authbox_warn_log { "HTTP request error: #{e}" }
96
98
  end
97
99
  end
98
100
  end
@@ -113,6 +115,23 @@ module Authbox
113
115
  return @authbox_pool
114
116
  end
115
117
 
118
+ def authbox_debug_log(&message_block)
119
+ # Rails doesn't have a great way to filter logging out of the box and we want
120
+ # this SDK to be as out-of-the-way as possible, so we gate all logging behind a
121
+ # config.
122
+ if Rails.configuration.authbox[:debug]
123
+ logger.tagged('AUTHBOX') {
124
+ logger.debug message_block
125
+ }
126
+ end
127
+ end
128
+
129
+ def authbox_warn_log(&message_block)
130
+ logger.tagged('AUTHBOX') {
131
+ logger.warn message_block
132
+ }
133
+ end
134
+
116
135
  def authbox_get_cookie(cookie_type)
117
136
  sha256 = Digest::SHA256.new
118
137
  return sha256.hexdigest(
@@ -126,7 +145,7 @@ module Authbox
126
145
 
127
146
  def authbox_ensure_one_request
128
147
  if @authbox_requested
129
- logger.warn 'authbox_log() already called'
148
+ authbox_warn_log { 'authbox_log() already called' }
130
149
  return false
131
150
  end
132
151
 
@@ -137,6 +156,10 @@ module Authbox
137
156
  def authbox_request(endpoint, action, async)
138
157
  cookie_name = authbox_get_cookie('local_machine_id')
139
158
 
159
+ if Rails.configuration.authbox[:api_key].nil? or Rails.configuration.authbox[:secret_key].nil?
160
+ authbox_warn_log { 'api_key and secret_key were not set' }
161
+ end
162
+
140
163
  if cookies[cookie_name].blank?
141
164
  local_machine_id = SecureRandom.hex(32)
142
165
  @authbox_new_local_machine_id = true
@@ -169,7 +192,11 @@ module Authbox
169
192
  '$ipAddress' => remote_ip,
170
193
  '$endpointURL' => request.original_url,
171
194
  '$apiKey' => Rails.configuration.authbox[:api_key],
172
- '$secretKey' => Rails.configuration.authbox[:secret_key]
195
+ '$secretKey' => Rails.configuration.authbox[:secret_key],
196
+ '$rails' => {
197
+ '$controller' => controller_name,
198
+ '$action' => action_name
199
+ }
173
200
  }
174
201
 
175
202
  body.merge!(authbox_get_request_data())
@@ -194,7 +221,7 @@ module Authbox
194
221
  return @authbox_verdict
195
222
  end
196
223
  rescue => e
197
- logger.warn "AUTHBOX: Error decoding body: #{e}"
224
+ authbox_warn_log { "Error decoding body: #{e}" }
198
225
 
199
226
  # Fail open
200
227
  @authbox_verdict = {'type' => 'ALLOW', 'info' => 'Error from server'}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Authbox, Inc.