在没有身份验证的情况下解码签名请求

在没有身份验证的情况下解码签名请求

本文介绍了在没有身份验证的情况下解码签名请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我正在寻找 .NET C# 等效于在此 PHP 示例中完成相同类型的解码:检查用户是否喜欢页面的无缝方式

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

推荐答案

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

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

Facebook 中仅限粉丝的内容asp.net C# SDK

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

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(""", "");
}

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

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

另请参阅如何为 C# 中的 Canvas 签名请求解码 OAuth 2.0? 如果您对签名请求感到厌烦.

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

这篇关于在没有身份验证的情况下解码签名请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 19:10