无需身份验证即可解码签名请求

发布于 2024-12-12 00:10:15 字数 358 浏览 0 评论 0原文

我们是否能够使用 Facebook C# SDK 来解码传递到 Facebook 选项卡页面的 signed_request 参数,不使用身份验证?基本上,我正在寻找一种方法来解码和解析signed_request 包含的页面 JSON 对象

我正在寻找相当于在这个 PHP 示例中完成相同类型解码的 .NET C#无缝地检查用户是否喜欢页面

Are we able to use the Facebook C# SDK to decode the signed_request parameter that is passed to the Facebook Tab page, without using Authentication? Basically, I am looking for a way to decode and parse the page JSON object that the signed_request contains.

I am looking for the .NET C# equivelent to accomplishing the same type of decode in this PHP example: Seamless way to check if user likes page

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

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

发布评论

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

评论(2

因为看清所以看轻 2024-12-19 00:10:15

我只是粘贴我在另一篇文章中回答过的相同答案。

带有 asp.net 的 facebook 中仅限粉丝观看的内容C# sdk

当您的网页在 facebook canvas 应用程序中加载时,您会收到签名请求;您应该能够解析类似于以下内容的签名请求:

if (Request.Params["signed_request"] != null)
{
    string payload = Request.Params["signed_request"].Split('.')[1];
    var encoding = new UTF8Encoding();
    var decodedJson = payload.Replace("=", string.Empty).Replace('-', '+').Replace('_', '/');
    var base64JsonArray = Convert.FromBase64String(decodedJson.PadRight(decodedJson.Length + (4 - decodedJson.Length % 4) % 4, '='));
    var json = encoding.GetString(base64JsonArray);
    var o = JObject.Parse(json);
    var lPid = Convert.ToString(o.SelectToken("page.id")).Replace("\"", "");
    var lLiked = Convert.ToString(o.SelectToken("page.liked")).Replace("\"", "");
    var lUserId= Convert.ToString(o.SelectToken("user_id")).Replace("\"", "");
}

您需要添加对 json 库的引用才能解析 C# 中的签名请求,请从 http://json.codeplex.com/

另请参阅如何在 C# 中解码 Canvassigned_request 的 OAuth 2.0 ? 如果您对签名请求感到厌倦。

I am just pasting same answer I have answered in another post.

Fans-only content in facebook with asp.net C# sdk

You get signed request when your web page is loaded within facebook canvas app; you should be able to parse signed request something similar to following:

if (Request.Params["signed_request"] != null)
{
    string payload = Request.Params["signed_request"].Split('.')[1];
    var encoding = new UTF8Encoding();
    var decodedJson = payload.Replace("=", string.Empty).Replace('-', '+').Replace('_', '/');
    var base64JsonArray = Convert.FromBase64String(decodedJson.PadRight(decodedJson.Length + (4 - decodedJson.Length % 4) % 4, '='));
    var json = encoding.GetString(base64JsonArray);
    var o = JObject.Parse(json);
    var lPid = Convert.ToString(o.SelectToken("page.id")).Replace("\"", "");
    var lLiked = Convert.ToString(o.SelectToken("page.liked")).Replace("\"", "");
    var lUserId= Convert.ToString(o.SelectToken("user_id")).Replace("\"", "");
}

You need to add reference to json libraries in order to parse signed requestin C#, download from http://json.codeplex.com/

Also refere to How to decode OAuth 2.0 for Canvas signed_request in C#? if you are worndering about signed request.

沫离伤花 2024-12-19 00:10:15

“未经身份验证”是什么意思?签名的请求是使用您的应用密钥进行签名的,因此无论当前用户是否授权您的应用,您都可以对其进行解码

{edit}我现在意识到您引用的是一个名为 Authentication 的库{/edit}

如果您找到其他库或重新实现 HMAC SHA-256 和 base64url 解码器的算法我确信您可以在不使用特定库的情况下做到这一点,但使用它可能更容易

What do you mean 'without authentication'? The signed request is signed with your app secret, so you can decode it regardless of whether the current user has authorised your app

{edit} I now realise you're referring to a library named Authentication{/edit}

If you find another library or reimplement the algorithm for HMAC SHA-256 and a base64url decoder i'm sure you could do it without using that specific library, but it's probably easier to just use it

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