验证签名 Facebook Connect

发布于 2024-07-14 05:18:44 字数 418 浏览 8 评论 0原文

我已按照这个伟大的Stackoverflow问题中的说明进行操作,但我不确定此验证签名的事情。 Facebook 工具包中是否以某种方式提供了此功能,还是我必须自己做一些事情? 文档对于如何执行此操作以及它是否已经烘焙并不非常清楚在 facebook 工具包中我不想花太多时间在上面。

有人做过这个吗? 应该提到我在 C# 中使用标准 ASP.NET Web 应用程序。 任何帮助,将不胜感激!

I have followed the instructions in this great Stackoverflow question but i am not sure about this verify signature thing. Is this provided in some way in the Facebook Toolkit or do i have to do something myself? The documentation is not superclear on how to do this and if it is already baked in the facebook toolkit i don't want to spend to much time on it.

Anyone have done this? Should mention i use a standard ASP.NET Web Application in C#. Any help would be appreciated!

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

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

发布评论

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

评论(2

夏末的微笑 2024-07-21 05:18:44

目前,你必须自己做。 我提供了一个简单的方法,您可以调用它来查看签名是否有效。

private bool IsValidFacebookSignature()
    {
        //keys must remain in alphabetical order
        string[] keyArray = { "expires", "session_key", "ss", "user" };
        string signature = "";

        foreach (string key in keyArray)
            signature += string.Format("{0}={1}", key, GetFacebookCookie(key));

        signature += SecretKey; //your secret key issued by FB

        MD5 md5 = MD5.Create();
        byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(signature.Trim()));

        StringBuilder sb = new StringBuilder();
        foreach (byte hashByte in hash)
            sb.Append(hashByte.ToString("x2", CultureInfo.InvariantCulture));

        return (GetFacebookCookie("") == sb.ToString());
    }

    private string GetFacebookCookie(string cookieName)
    {
        //APIKey issued by FB
        string fullCookie = string.IsNullOrEmpty(cookieName) ? ApiKey : ApiKey + "_" + cookieName;

        return Request.Cookies[fullCookie].Value;
    }

注意:SecretKey 和 ApiKey 是 Facebook 提供的值,您需要设置。

At the moment, you have to do it yourself. I've provided a simple method you can call to see if the signature is valid or not.

private bool IsValidFacebookSignature()
    {
        //keys must remain in alphabetical order
        string[] keyArray = { "expires", "session_key", "ss", "user" };
        string signature = "";

        foreach (string key in keyArray)
            signature += string.Format("{0}={1}", key, GetFacebookCookie(key));

        signature += SecretKey; //your secret key issued by FB

        MD5 md5 = MD5.Create();
        byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(signature.Trim()));

        StringBuilder sb = new StringBuilder();
        foreach (byte hashByte in hash)
            sb.Append(hashByte.ToString("x2", CultureInfo.InvariantCulture));

        return (GetFacebookCookie("") == sb.ToString());
    }

    private string GetFacebookCookie(string cookieName)
    {
        //APIKey issued by FB
        string fullCookie = string.IsNullOrEmpty(cookieName) ? ApiKey : ApiKey + "_" + cookieName;

        return Request.Cookies[fullCookie].Value;
    }

Note: SecretKey and ApiKey are values provided by Facebook that you need to set.

老旧海报 2024-07-21 05:18:44

您可以使用 FBConnectAuth 来完成此操作,它的作用与上面相同,而且还多了一点。

You can do this using FBConnectAuth, it does the same as above, and a little more.

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