Reputation: 2368
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}×tamp=#{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?
Upvotes: 0
Views: 209
Reputation: 4164
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}×tamp=#{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.
Upvotes: 0
Reputation: 2368
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.
Upvotes: 0