我正在尝试为Disquss实现单点登录功能。Disquss有一个测试控制台,它使我们能够快速测试这些值。首先,我们确保获得了用于控制台的硬编码值,因此我们确信我们理解Disquss的需求。接下来,我们想在rails中实现相同的东西,但这里有问题。
问题在于,红宝石并没有产生预期值,实际上它会产生垃圾,这与期望值完全不同:
THis来自Disquss手册:
消息体(Base64 64编码)
邮件正文必须包括下列区分大小写的属性,除非另有说明:
id - any unique user ID associated with that account within your user database. This will be used to generate a unique username to reference in the Disqus system. IDs must be completely unique; if you're using multiple datastores locally, for example, make sure not to re-use IDs when passing them to Disqus as that will result in account conflicts.
username - The displayed name for that account
email - The registered email address for that account
avatar (optional) - A link to that user's avatar
url (optional) - A link to the user's websiteHMAC-SHA1 1签名
使用HMAC->SHA1 1(secret_key,message +‘’+时间戳)生成
遵循这个示例,我们设计了如下的rails代码(它仍然处于测试阶段,因此是puts):
secret_key = "12312312312312312312312312312312312312312312312312"
digest = OpenSSL::Digest::Digest.new('sha1')
puts @disqus_timestamp = Date.today.to_time.to_i
puts @disqus_serializer_message = {"id"=> session[:frontend_user].to_s,"username"=>@fuser.username,"email"=>@fuser.email }.to_json
puts @disqus_message = Base64.encode64(@disqus_serializer_message)
puts @disqus_signature = OpenSSL::HMAC.digest(digest,secret_key,@disqus_message + ' '+ @disqus_timestamp.to_s )
puts @sso_payload = ""
puts "END"我们应该获得三个值: 1.以格式序列化的JSON,如:
eyJ1c2VybmFtZSI6InZlZHJhbiBtYXJpY2V2aWMiLCJpZCI6IjgiLCJlbWFp bCI6IndleC5hbHBoYUBnbWFpbC5jb20ifQ==
Json作品
5名œ[ƒm`™`∆“≠∆8
但我们应该得到这种形式的东西:
4683eff451100191c60d2a0f0e72f3a6d15db950
我尝试了不同的东西,但都没有用。有什么问题吗?
发布于 2013-03-13 13:26:50
OpenSSL::HMAC.digest输出原始字节,而您似乎想要十六进制表示
OpenSSL::HMAC.hexdigest将以十六进制格式输出。当然,你也可以自己转换它:
arbitary_data.unpack('H*').first
会对所有的字节进行编码。
发布于 2013-11-13 18:20:27
我也遇到了类似的问题,使用http://disqus.com/api/sso/上的Debuger,我确定消息在执行Base64编码时得到了一个中断行。
参考base64 encode length parameter
我改变了
puts @disqus_message = Base64.encode64(@disqus_serializer_message) 至
puts @disqus_message = Base64.strict_encode64(@disqus_serializer_message)现在它运转得很好。
https://stackoverflow.com/questions/15386122
复制相似问题