【问题标题】:Generating oauth_signature for Netflix为 Netflix 生成 oauth_signature
【发布时间】:2011-08-24 04:20:08
【问题描述】:

我正在尝试生成用于 Netflix 的 oauth 签名。我一直在关注他们的 API 文档,但是当他们到达“If you are using a library, once you have created your base string, it is easy to generate the signature. You pass your base string and your shared secret to a function and get the signature back. See the OAuth Code Page for examples”的行时遇到问题。

我可以创建我的基本字符串并拥有我的共享密钥,但不知道如何使用Oauth gem 来生成签名。

任何帮助都会很棒。

【问题讨论】:

    标签: ruby-on-rails-3 netflix


    【解决方案1】:

    您是否查看过omniauth 策略以获取提示? https://github.com/spagalloco/omniauth-netflix/blob/master/lib/omniauth/strategies/netflix.rb -- 开源之美..

    【讨论】:

      【解决方案2】:

      我最终手动创建了 Oauth 签名,而不是使用 gem:

        plain_url = "#{NETFLIX_PUBLIC_URL}"+"#{NETFLIX_TOKEN_ACCESS}"
      
      
         latest_time = "#{Time.now.to_i}"
         nonce = rand(1_000_000)
         token_string="oauth_consumer_key=#{NETFLIX_KEY}&oauth_nonce=#{nonce}&oauth_signature_method=HMAC-SHA1&oauth_timestamp=#{latest_time}" +
             "&oauth_token=#{oauth_token}&oauth_version=1.0"
      
         encoded_string = CGI.escape(token_string)
         encoded_url = CGI.escape(plain_url)
         signature_string=  "GET&"+encoded_url+"&"+encoded_string
         puts "signature string is " + signature_string
      
         signature_key = "#{NETFLIX_SECRET}&#{token_secret}"
      
         signature = Base64.encode64(HMAC::SHA1.digest( signature_key,signature_string)).chomp.gsub(/\n/,'')
      
         encoded_signature = CGI.escape(signature)
         call = plain_url + "?" + token_string + "&oauth_signature="+encoded_signature
      

      【讨论】:

      • token_string 中的 oauth_token 是什么?和 NETFLIX_TOKEN_ACCESS 一样吗?
      【解决方案3】:

      你是这个意思吗:

      OAuth::Signature.signature_base_string(request, options = {}, &block)
      

      http://www.rubydoc.info/gems/oauth/0.4.7/OAuth/Signature

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-03-15
        • 1970-01-01
        • 2011-11-27
        • 1970-01-01
        • 2018-09-24
        • 2015-11-27
        • 1970-01-01
        相关资源
        最近更新 更多