authbox 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/authbox.rb +45 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddf5c8f090baec72a6aa598fbb2e4598ec1bd238
4
- data.tar.gz: 5648ec3da5624749cdcb19cef90449361d227410
3
+ metadata.gz: acc525e74ec5937d46906f9e1f682638c7dbce9c
4
+ data.tar.gz: cebb588c2567adb44f391d54314dc416be283d77
5
5
  SHA512:
6
- metadata.gz: 1d349e8cf24f32a879603858da81e19654b96d7fd6f172115d48ae65b3c3de8f8d4c2d374a6a2a2b9c0a2fbbb7f37b3614ad7f7bd5aae608bf6eb02fc95949fe
7
- data.tar.gz: ffbaa80f215f50e92d415db7f9d67b1ad94c656f4ac72ba838882e9b1ceef186411607c4ae5e452138121706c62c8ed7de89106feb42bad963eff0c28f0bea8d
6
+ metadata.gz: 37e6bd3aa6c75788b93eb0a2ae44b1ce1fbe37938a610c46b54a5b7716d35c6b8301541fa343794bad2d60efba3ae2e6662d54ed93e0ee813350b0f465027f56
7
+ data.tar.gz: a8f53a2318c8a7b6311fb9a8d0f6286e20461430db3205cdb7b37fe16c5071170a827aba1b9991cae61f9d4973a137c79acd4f6ee7cfd88e42a65a8810a408bd
data/lib/authbox.rb CHANGED
@@ -55,7 +55,31 @@ module Authbox
55
55
  # will be logged. See the documentation for what information
56
56
  # you can pass here in the action hash.
57
57
  def authbox_log(action={})
58
- return authbox_request(action, true)
58
+ if not authbox_ensure_one_request()
59
+ return @authbox_verdict
60
+ end
61
+
62
+ return authbox_request('/action', action, true)
63
+ end
64
+
65
+ def authbox_check(action={})
66
+ if not authbox_ensure_one_request()
67
+ return @authbox_verdict
68
+ end
69
+
70
+ return authbox_request('/action', action, false)
71
+ end
72
+
73
+ def authbox_begin(action={})
74
+ if not authbox_ensure_one_request()
75
+ return @authbox_verdict
76
+ end
77
+
78
+ return authbox_request('/action_begin', action, false)
79
+ end
80
+
81
+ def authbox_end(action={})
82
+ return authbox_request('/action_end', action, false)
59
83
  end
60
84
 
61
85
  ##
@@ -100,21 +124,26 @@ module Authbox
100
124
  return Rails.configuration.authbox[:endpoint] || 'https://api.authbox.io/api'
101
125
  end
102
126
 
103
- def authbox_request(action, async)
127
+ def authbox_ensure_one_request
104
128
  if @authbox_requested
105
129
  logger.warn 'authbox_log() already called'
106
- return
130
+ return false
107
131
  end
108
132
 
109
133
  @authbox_requested = true
134
+ return true
135
+ end
110
136
 
137
+ def authbox_request(endpoint, action, async)
111
138
  cookie_name = authbox_get_cookie('local_machine_id')
112
139
 
113
140
  if cookies[cookie_name].blank?
114
141
  local_machine_id = SecureRandom.hex(32)
142
+ @authbox_new_local_machine_id = true
115
143
  @authbox_insert_pixel = true
116
144
  else
117
145
  local_machine_id = cookies[cookie_name]
146
+ @authbox_new_local_machine_id = false
118
147
  end
119
148
 
120
149
  cookies[cookie_name] = {
@@ -132,9 +161,13 @@ module Authbox
132
161
 
133
162
  body = {
134
163
  '$actionName' => '$unknown',
135
- '$localMachineID' => local_machine_id,
164
+ '$localMachineID' => {
165
+ '$key' => local_machine_id,
166
+ '$new' => @authbox_new_local_machine_id
167
+ },
136
168
  '$userAgent' => request.user_agent,
137
169
  '$ipAddress' => remote_ip,
170
+ '$endpointURL' => request.original_url,
138
171
  '$apiKey' => Rails.configuration.authbox[:api_key],
139
172
  '$secretKey' => Rails.configuration.authbox[:secret_key]
140
173
  }
@@ -143,7 +176,7 @@ module Authbox
143
176
  body.merge!(action)
144
177
 
145
178
  base_uri = authbox_get_endpoint()
146
- uri = URI(base_uri + '/action')
179
+ uri = URI(base_uri + endpoint)
147
180
 
148
181
  if async
149
182
  Authbox.authbox_pool.process do
@@ -157,14 +190,19 @@ module Authbox
157
190
  begin
158
191
  parsed_response = JSON.parse(response.body)
159
192
  if not parsed_response.has_key? 'type'
160
- return {'type' => 'ALLOW', 'info' => 'No verdict returend'}
193
+ @authbox_verdict = {'type' => 'ALLOW', 'info' => 'No verdict returend'}
194
+ return @authbox_verdict
161
195
  end
162
196
  rescue => e
163
197
  logger.warn "AUTHBOX: Error decoding body: #{e}"
164
198
 
165
199
  # Fail open
166
- return {'type' => 'ALLOW', 'info' => 'Error from server'}
200
+ @authbox_verdict = {'type' => 'ALLOW', 'info' => 'Error from server'}
201
+ return @authbox_verdict
167
202
  end
203
+
204
+ @authbox_verdict = parsed_response
205
+ return @authbox_verdict
168
206
  end
169
207
 
170
208
  included do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Authbox, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-20 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thread