1

Disquss のシングル サインオン機能を実装しようとしています。Disquss にはテスト コンソールがあり、値をすばやくテストできます。まず、コンソールで動作するようにハードコードされた値を取得したことを確認したため、Disquss の要件を確実に理解できました。次に、Rails で同じことを実装したかったのですが、ここで問題が発生しました。

問題は、Ruby が期待値を生成していないという事実にあります。実際には、期待値とはまったく異なるジャンクが生成されます。

これは Disquss マニュアルからのものです。

メッセージ本文 (Base64 エンコード)

メッセージ本文には、特に明記されていない限り、次の大文字と小文字を区別するプロパティを含める必要があります。

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 website

HMAC-SHA1 署名

HMAC->SHA1(secret_key、メッセージ + ' ' + タイムスタンプ) を使用して生成

その例に続いて、次の 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"

3 つの値を取得する必要があります。 1. 次のような形式でシリアル化された JSON。

eyJ1c2VybmFtzSI6InZlZHJhbiBtYXJpY2V2aWMiLCJpZCI6IjgiLCJlbWFp bCI6IndleC5hbHBoYUBnbWFpbC5jb20ifQ==

ジェイソン・ワークス

  1. 計算された HMAC: このタイプの形式を取得しています。

5œ[ƒmò Ø™`Õ„Öù©≠Δ8

しかし、次の形式で何かを取得する必要があります。

4683eff451100191c60d2a0f0e72f3a6d15db950

いろいろ試してみましたがだめでした。何が問題なのですか?

4

2 に答える 2

0

私も同様の問題を抱えていました。http://disqus.com/api/sso/ で Disqus SSO Debuger を使用したところ、Base64 エンコーディングを行っているときにメッセージに改行が追加されていることがわかりました。

base64 エンコード長パラメーターの参照

私が変更され

puts  @disqus_message = Base64.encode64(@disqus_serializer_message)    

puts  @disqus_message = Base64.strict_encode64(@disqus_serializer_message)

そして今、それはうまく機能しています。

于 2013-11-13T18:20:27.643 に答える