4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/ronin_security.rb', line 4
def self.enforce(url, request)
puts request
response = HTTParty.get(url)
authorizationResponse = JSON.parse(response.body)
puts authorizationResponse["authorized"]
otp = request.["HTTP_OTP"]
humantoken = request.["HTTP_HUMANTOKEN"]
devicetoken = request.["HTTP_DEVICE_TOKEN"]
ip = request.remote_ip
if ip == "::1" || ip == "127.0.0.1"
realIpData = HTTParty.get("https://api.ipify.org?format=json")
puts realIpData
parsedIpData = JSON.parse(realIpData.body)
ip = parsedIpData["ip"]
end
possibletoken = request.["HTTP_TOKEN"].split("Bearer ")
token = request.["HTTP_TOKEN"] || possibletoken
= {
"method" => request.method,
"ip" => ip,
"token" => token,
"api" => request.original_url.split(request.original_fullpath)[0],
"action" => request.original_fullpath,
"fullActionPath" => request.original_url
}
if devicetoken != nil
["device_token"] = devicetoken
end
if otp != nil
["otp"] = otp
end
if humantoken != nil
["humantoken"] = humantoken
end
authorizedMessage = HTTParty.get(url, :headers => )
authorizationResult = JSON.parse(authorizedMessage.body)
return authorizationResult
end
|