【问题标题】:Example code of FBML App that uses signed_request?使用 signed_request 的 FBML 应用程序示例代码?
【发布时间】:2011-10-01 08:08:52
【问题描述】:

我们不知道 10 月 1 日也是 signed_request 的截止日期。 有没有人有示例代码来为 FBML 应用程序做签名请求? 我们正努力赶上 10 月 1 日的最后期限。谢谢!

【问题讨论】:

    标签: facebook-graph-api fbml oauth-2.0


    【解决方案1】:

    signed_request documentation 展示了如何在 PHP 中执行此操作。用任何语言都很容易做到。

    function parse_signed_request($signed_request, $secret) {
      list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
    
      // decode the data
      $sig = base64_url_decode($encoded_sig);
      $data = json_decode(base64_url_decode($payload), true);
    
      if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
        error_log('Unknown algorithm. Expected HMAC-SHA256');
        return null;
      }
    
      // check sig
      $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
      if ($sig !== $expected_sig) {
        error_log('Bad Signed JSON signature!');
        return null;
      }
    
      return $data;
    }
    
    function base64_url_decode($input) {
      return base64_decode(strtr($input, '-_', '+/'));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-17
      相关资源
      最近更新 更多