0

I am having a very hard time getting access to the quickblox API. Based on their documentation this code should work:

 require 'base64'
  require 'cgi'
  require 'openssl'
  require 'hmac-sha1'

  # Application credentials
  aPPLICATION_ID = 12345
  aUTH_KEY = 'hidden'
  aUTH_SECRET = 'hidden'


  # Generate signature
  timestamp = Time.now.in_time_zone('UTC').to_i
  nonce = timestamp-425346
  signature_string = "application_id=#{aPPLICATION_ID}&auth_key=#{aUTH_KEY}&nonce=#{nonce}&timestamp=#{timestamp}"
  signature =Base64.encode64("#{ OpenSSL::HMAC.digest('sha1', signature_string, aUTH_SECRET) }")

  # Post
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  request = Net::HTTP::Post.new("/session.json")
  request.add_field('QuickBlox-REST-API-Version', '0.1.1')
  request.add_field('Content-Type', 'application/json')
  request.add_field('Accept', '*/*')
  request.body = {"application_id" => aPPLICATION_ID, "auth_key" => aUTH_KEY, "nonce" => nonce, "timestamp" => timestamp, "signature" => signature }.to_json

  response = http.request(request)

However I keep getting an error: {"errors":{"base":["Unexpected signature"]}}

Even when using their hurl: http://hurl.quickblox.com/ i get the exact same error. Very frustrating. What exactly am I doing wrong?

Steffan Perry
  • 2,112
  • 1
  • 21
  • 21
  • Try the following: signature_string = "application_id=#{aPPLICATION_ID}&auth_key=#{aUTH_KEY}&nonce=#{nonce}&timestamp=#{timestamp}" signature = HMAC::SHA1.hexdigest(aUTH_SECRET, signature_string) – Darya Mar 10 '16 at 12:27

2 Answers2

0

As it turns out, it looks like QuickBlox does not accept the signature has produced by ruby for some reason. QuickBlox even removed their own ruby gem (in which also generates this same error).

Right now the solution is to grab the token via a php script first then do your calls in ruby.

Steffan Perry
  • 2,112
  • 1
  • 21
  • 21
0

Check my stackoverflow answer on this issue here.

This mostly boils down to these two lines:

signature_string = "application_id=#{aPPLICATION_ID}&auth_key=#{aUTH_KEY}&nonce=#{nonce}&timestamp=#{timestamp}"

signature =Base64.encode64("#{ OpenSSL::HMAC.digest('sha1', signature_string, aUTH_SECRET) }")

You can check this quickblox_api gem too. It worked greatly for me.

Community
  • 1
  • 1
x6iae
  • 4,074
  • 3
  • 29
  • 50