1

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!

4

2 に答える 2

1

現時点では、自分で行う必要があります。署名が有効かどうかを確認するために呼び出すことができる簡単なメソッドを提供しました。

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 によって提供される値です。

于 2009-06-03T02:40:03.460 に答える
0

FBConnectAuthを使用してこれを行うことができます。これは上記と同じで、もう少し多くのことを行います。

于 2009-08-26T23:02:33.637 に答える