【问题标题】:What's purpose of facebook application keyfacebook应用程序密钥的用途是什么
【发布时间】:2011-02-11 16:29:00
【问题描述】:

当您注册一个 facebook 应用程序时,您将获得

申请编号:123455678 应用程序密钥:hkjhkh3434hkklljk 申请秘籍:jkjljlj1233455jk

对于 OAuth 2,只有应用程序 ID(a.k.a.client_id)和应用程序密码(a.k.a.client_secret)是有用的。

想知道应用程序密钥的用途是什么?是出于某种后端目的吗?如果是,那暴露的意义何在。

【问题讨论】:

    标签: facebook key oauth-2.0


    【解决方案1】:

    我只是在这里大声思考。

    我想这只是为了向后兼容,特别是旧的Facebook Connect 实现和使用APP_KEY 的REST API。

    正如您在FB.init Javascript-SDK 中看到的那样:

    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId  : 'YOUR APP ID',
          status : true, // check login status
          cookie : true, // enable cookies to allow the server to access the session
          xfbml  : true  // parse XFBML
        });
      };
    
      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
      }());
    </script>
    

    他们没有提到apiKey,这是与 PHP-SDK 一起使用的代码。
    现在如果你去旧的connect-js example

    FB.init({ apiKey: '48f06bc570aaf9ed454699ec4fe416df' });
    

    所以调试connect.facebook.net/en_US/all.js文件(使用JSBeautifier):

    FB.provide('', {
        init: function (a) {
            a = FB.copy(a || {}, {
                logging: true,
                status: true
            });
            FB._apiKey = a.appId || a.apiKey;
            if (!a.logging && window.location.toString().indexOf('fb_debug=1') < 0) FB._logging = false;
            FB.XD.init(a.channelUrl);
            if (FB._apiKey) {
                FB.Cookie.setEnabled(a.cookie);
                a.session = a.session || FB.Cookie.load();
                FB.Auth.setSession(a.session, a.session ? 'connected' : 'unknown');
                if (a.status) FB.getLoginStatus();
            }
            if (a.xfbml) window.setTimeout(function () {
                if (FB.XFBML) FB.Dom.ready(FB.XFBML.parse);
            }, 0);
        }
    });
    

    您可以在这里看到它正在检查 apiIdapiKey 的存在,然后尝试调用图形 api 和 else 其余 api:

    FB.provide('', {
        api: function () {
            if (typeof arguments[0] === 'string') {
                FB.ApiServer.graph.apply(FB.ApiServer, arguments);
            } else FB.ApiServer.rest.apply(FB.ApiServer, arguments);
        }
    });
    

    还有:

    graph: function () {
        var a = Array.prototype.slice.call(arguments),
            f = a.shift(),
            d = a.shift(),
            c, e, b;
        while (d) {
            var g = typeof d;
            if (g === 'string' && !c) {
                c = d.toLowerCase();
            } else if (g === 'function' && !b) {
                b = d;
            } else if (g === 'object' && !e) {
                e = d;
            } else {
                FB.log('Invalid argument passed to FB.api(): ' + d);
                return;
            }
            d = a.shift();
        }
        c = c || 'get';
        e = e || {};
        if (f[0] === '/') f = f.substr(1);
        if (FB.Array.indexOf(FB.ApiServer.METHODS, c) < 0) {
            FB.log('Invalid method passed to FB.api(): ' + c);
            return;
        }
        FB.ApiServer.oauthRequest('graph', f, c, e, b);
    },
    rest: function (e, a) {
        var c = e.method.toLowerCase().replace('.', '_');
        if (FB.Auth && c === 'auth_revokeauthorization') {
            var d = a;
            a = function (f) {
                if (f === true) FB.Auth.setSession(null, 'notConnected');
                d && d(f);
            };
        }
        e.format = 'json-strings';
        e.api_key = FB._apiKey;
        var b = FB.ApiServer._readOnlyCalls[c] ? 'api_read' : 'api';
        FB.ApiServer.oauthRequest(b, 'restserver.php', 'get', e, a);
    },
    

    正如您在此处看到的,它与Old Rest API 一起使用,阅读那里的文档:

    REST API 同时支持 OAuth 2.0 以及较旧的自定义 授权签名方案。看 身份验证升级指南 有关如何升级您的 与 OAuth 2.0 的现有会话。

    所以APP_KEY 肯定是为了向后兼容!

    【讨论】:

    • 我觉得有道理,肯定是为了向后兼容。我还注意到,对于注销,仍然需要应用程序密钥,例如,要注销,调用 http://www.facebook.com/logout.php?api_key={application key}&amp;;session_key={oauth 2.0 code}"; 对于 OAuth 2.0 兼容性,它应该是 http://www.facebook.com/logout.php?api_id={client_id}&amp;;app_secret={client_secret}&amp;;session_key={oauth 2.0 code}; 或只是 http://www.facebook.com/logout.php?session_key={oauth 2.0 code}; 它看起来像 facebook在实施 OAuth 2.0 方面不一致。
    • @user613343:好吧,使用他们的 PHP-SDK...从$facebook-&gt;getLogoutUrl() 调用生成的注销 URL 看起来像:https://www.facebook.com/logout.php?next=http://domain.com/&amp;access_token=XXXXXXXX
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 2020-02-17
    • 2011-10-14
    • 1970-01-01
    • 2011-05-22
    • 2011-12-05
    相关资源
    最近更新 更多