QuickBlox Session create: Unexpected Signature in

2019-09-14 13:10发布

问题:

I am trying to create QuickBlox session from Rest API using Ruby on Rails. My current implementation:

def qb_signin_params
  timestamp = Time.now.in_time_zone('UTC').to_i
  nonce = rand.to_s[2..6]
  signature_string = "application_id=#{QuickBlox_Application_Id}&auth_key=#{QUICKBLOX_Authorization_KEY}&nonce=#{nonce}&timestamp=#{timestamp}"
  digest = OpenSSL::Digest.new('sha1')
  signature = OpenSSL::HMAC.hexdigest(digest, signature_string, QUICKBLOX_Authorization_SECRET)

  params = Hash.new
  params['application_id'] = QuickBlox_Application_Id
  params['auth_key'] = QUICKBLOX_Authorization_KEY
  params['timestamp'] = timestamp
  params['nonce'] = nonce
  params['signature'] = signature

  params
end

Returns following error:

unexpected token at '<?xml version="1.0" encoding="UTF-8"?>
<errors> 
  <error>Unexpected signature</error>
</errors>

I have searched through several places, but could never find the correct Signature generation for Ruby. Please help.

回答1:

Check out this quickblox_api gem. It worked great for me...

I was having this same issue, and on looking at what was done in there, which was almost exactly what you ( and I ) were doing... apart from the fact that the body for the hmac_sha was getting sorted alphabetically, as instructed/mentioned on the quickblox documentation which I quote below:

Request body is formed as the sorted (sorting alphabetically, as symbols, not as bytes) by increase the string array 'parameter=value', separated with the symbol "&"