简体   繁体   English

我如何在Facebook之外禁用Facebook iframe应用

[英]How do i disable the facebook iframe app outside of facebook

I've created a iframe facebook app and i want to disable the app outside of facebook, that the user can't open the app via direct url. 我已经创建了一个iframe Facebook应用,并且我想在Facebook之外禁用该应用,因为该用户无法通过直接URL打开该应用。 I found a solution with javascript, but i need it in PHP. 我找到了使用javascript的解决方案,但是我需要在PHP中使用它。

I can't use the referrer, because some user have disabled it in there browser... 我无法使用引荐来源网址,因为某些用户已在该浏览器中将其禁用...

You can check if there's signed_request param sent in request. 您可以检查请求中是否发送了signed_request参数。 If application is opened inside facebook than signed_request exists. 如果在Facebook内部打开应用程序,则不存在signed_request。

But there's one more issue. 但是还有一个问题。
You should check if signed_request is valid and for that you can use parse_signed_request method 您应该检查signed_request是否有效,可以使用parse_signed_request方法

public function parse_signed_request($signed_request, $secret) { list($encoded_sig, $payload) = explode('.', $signed_request, 2); 公共功能parse_signed_request($ signed_request,$ 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') {
        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;
}

Then you can check if $data['user_id'] exist or is it equal to logged in user. 然后,您可以检查$ data ['user_id']是否存在或等于已登录的用户。 If not you can redirect like this 如果没有,您可以像这样重定向
echo "< script type='text/javascript' >top.location.href = '$this->loginUrl'; < /script >"; echo“ <脚本类型='文本/ javascript'> top.location.href ='$ this-> loginUrl'; </脚本>”; Or find some way to redirect from php. 或找到一些从php重定向的方法。 (There was redirect method in the old php sdk) (在旧的PHP SDK中有重定向方法)

您唯一的真实选择是尝试以某种方式使用Facebook API,然后查看是否收到任何响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM