Facebook 聊天 - X-FACEBOOK-PLATFORM 身份验证

发布于 2024-09-24 01:14:53 字数 105 浏览 0 评论 0原文

我想在 Android 上构建一个 XMPP 客户端,我已经使用 Digest-MD-5 进行身份验证使其完美运行,但是当我尝试将其转换为 X-FACEBOOK-PLATFORM 时,它一直失败。

I want to build an XMPP client on android, I've got it running perfect with authentication using Digest-MD-5, however when I try to convert it to X-FACEBOOK-PLATFORM it keeps failing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

快乐很简单 2024-10-01 01:14:53

因此基本上 X-FACEBOOK-PLATFORM 身份验证仅使用访问令牌的一部分。这称为会话密钥。

访问令牌由“|”分隔字符,因此您可以分割访问令牌并仅获取中间的字符。请参阅下文。

******|a681464febcefb8 *-**| ******

long callId = new GregorianCalendar().getTimeInMillis() / 1000L;

            String sig = "api_key=" + apiKey
                            + "call_id=" + callId
                            + "method=" + method
                            + "nonce=" + nonce
                            + "session_key=" + sessionKey
                            + "v=" + version
                            + appSecret;

            try {
                sig = MD5(sig);
            }
            catch (NoSuchAlgorithmException e) {
                throw new IllegalStateException(e);
            }

            String composedResponse = "api_key=" + URLEncoder.encode(apiKey, "utf-8")
                                        + "&call_id=" + callId
                                        + "&method=" + URLEncoder.encode(method, "utf-8")
                                        + "&nonce=" + URLEncoder.encode(nonce, "utf-8")
                                        + "&session_key=" + URLEncoder.encode(sessionKey, "utf-8")
                                        + "&v=" + URLEncoder.encode(version, "utf-8")
                                        + "&sig=" + URLEncoder.encode(sig, "utf-8");

So basically the X-FACEBOOK-PLATFORM authentication uses only a part of a access token. That is called the session key.

The access token is seperated by "|" characters, so you split the access token and only take the characters that are in the center. Refer below.

******|a681464febcefb8*-**|******

long callId = new GregorianCalendar().getTimeInMillis() / 1000L;

            String sig = "api_key=" + apiKey
                            + "call_id=" + callId
                            + "method=" + method
                            + "nonce=" + nonce
                            + "session_key=" + sessionKey
                            + "v=" + version
                            + appSecret;

            try {
                sig = MD5(sig);
            }
            catch (NoSuchAlgorithmException e) {
                throw new IllegalStateException(e);
            }

            String composedResponse = "api_key=" + URLEncoder.encode(apiKey, "utf-8")
                                        + "&call_id=" + callId
                                        + "&method=" + URLEncoder.encode(method, "utf-8")
                                        + "&nonce=" + URLEncoder.encode(nonce, "utf-8")
                                        + "&session_key=" + URLEncoder.encode(sessionKey, "utf-8")
                                        + "&v=" + URLEncoder.encode(version, "utf-8")
                                        + "&sig=" + URLEncoder.encode(sig, "utf-8");
橘虞初梦 2024-10-01 01:14:53

我从来没有让 FB 聊天与我的 appSecret 一起使用,而是使用了 sessionSecret。您可以使用旧的 REST API 获取它。

http://developers.facebook.com/docs/reference/rest/auth。 PromotionSession/

这样您就可以将您的 appSecret 保密。另外值得注意的是,X-FACEBOOK-PLATFORM 身份验证很少会在第一次尝试时成功,但通常需要 3-6 次重试。尽管我使用相同的会话密钥和秘密,但还是让我无法理解为什么。

I never got FB chat to work with my appSecret but used sessionSecret instead. You can get it using oldish REST API.

http://developers.facebook.com/docs/reference/rest/auth.promoteSession/

This way you can keep your appSecret as a secret. Also it's worth noticing X-FACEBOOK-PLATFORM authentication rarely succeeds on first try but requires 3-6 retries usually. Beats me why though as I'm using same session key and secret..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文