QuickBlox Session create: Unexpected Signature in Rails App

巧了我就是萌 提交于 2019-12-13 06:59:36

问题


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 "&"



来源:https://stackoverflow.com/questions/37186306/quickblox-session-create-unexpected-signature-in-rails-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!