SHARE
TWEET

Untitled

a guest May 19th, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local HTTPService = game:GetService("HttpService")
  2. local lockbox = require(script.Parent.lockbox)
  3. lockbox.bit = require(script.Parent.bit).bit
  4. local array = require(lockbox.util.array)
  5. local stream = require(lockbox.util.stream)
  6. local base64 = require(lockbox.util.base64)
  7. local hmac = require(lockbox.mac.hmac)
  8. local sha256 = require(lockbox.digest.sha2_256)
  9.  
  10. local secretKey = "16813a12f718bc5c620f56944e1abc3ea13ccbac"
  11.  
  12. local function hmacAuthHash(body, key)
  13.     local hmacBuilder = hmac()
  14.         .setBlockSize(64)
  15.         .setDigest(sha256)
  16.         .setKey(array.fromString(key))
  17.         .init()
  18.         .update(stream.fromString(body))
  19.         .finish()
  20.     return base64.fromArray(hmacBuilder.asBytes())
  21. end
  22.  
  23. function Request_Init(endpoint)
  24.     local InitPayload = {
  25.         ["platform"] = "ios",
  26.         ["os_version"] = "ios 8.2",
  27.         ["sdk_version"] = "rest api v2"
  28.     }
  29.     local InitPayloadJSON = HTTPService:JSONEncode(InitPayload)
  30.    
  31.     local Headers = {
  32.         ["Authorization"] =  hmacAuthHash(InitPayloadJSON, secretKey)
  33.     }
  34.    
  35.     local success, InitResponse = pcall(function() return HTTPService:PostAsync(endpoint,InitPayloadJSON,Enum.HttpContentType.ApplicationJson, false, Headers) end)
  36.  
  37.     if not success then
  38.         print("PostAsync Error for endpoint",endpoint,"        ERROR:",InitResponse)
  39.         return
  40.     else
  41.         print("PostAsync Success for endpoint",endpoint,"      RESPONSE:",InitResponse)
  42.         return
  43.     end
  44. end
  45.  
  46. Request_Init("http://sandbox-api.gameanalytics.com/v2/5c6bcb5402204249437fb5a7a80a4959/init")
RAW Paste Data
Top