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
|
# File 'lib/mvx_auth_client.rb', line 11
def request_token(login, password)
json = {:login => login, :password => password }
create_connection(AUTH_URL, '/login')
res = send_request(json)
token = JSON.parse(res.body)['login_token']
if token.blank?
return nil
end
user_info = decrypt_token_full(token)
if user_info.blank?
return nil
end
opcode = user_info[:opcode]
warehouseId = user_info[:warehouses].keys.first.to_s
new_token_request = { warehouseId: warehouseId }.to_json
cookie = 'Bearer ' + token
uri = URI.parse(AUTH_URL + "/get_tokens")
http = Net::HTTP.new(uri.host,uri.port, nil)
req = Net::HTTP::Post.new(uri.path, = {'Content-Type' =>'application/json'})
req['Authorization'] = cookie
req.body = new_token_request
res = http.request(req)
json_reply_hash = JSON.parse(res.body)
json_reply_hash[:opcode] = opcode
return json_reply_hash
end
|