使用 SignedRequest 而不是 accessToken 接缝是我需要的正确选择,例如 PHP 解决方案,使用应用程序机密。
private function check_signed_request($signed_request) {
$secret = Semods_Utils::getSetting('socialdna.facebook_secret','');
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = $this->base64_url_decode($encoded_sig);
$data = json_decode($this->base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
throw new Exception('Unknown algorithm. Expected HMAC-SHA256');
}
// Adding the verification of the signed_request below
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
throw new Exception('Bad Signed JSON signature!');
}
return true;
}
private function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
见:https ://developers.facebook.com/docs/howtos/login/signed-request/
问题
我没有收到签名请求,这些是未定义的:
response.authResponse.signed_request
response.authResponse.signedRequest
而这个只包含“...”
response.authResponse.sig
任何人的想法?
编辑
好的 .sig 接缝仅由我的插件提供,硬编码:所以修复应该在那里https://github.com/davejohnson/phonegap-plugin-facebook-connect
但报道:
https ://github.com/davejohnson/phonegap-plugin-facebook-connect/issues/245