Facebook的C#SDK签名的请求是空的IsAuthorized() [英] Facebook C# SDK signed request is null in IsAuthorized()

查看:128
本文介绍了Facebook的C#SDK签名的请求是空的IsAuthorized()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我研究关于在标题中提到的话题。方案说(除这个)的precondition失败!string.IsNullOrEmpty(settings.AppId)例外通过 FacebookWebContext.IsAuthorized()抛出是由没有引起设置签名的请求,其可以从查询串得到。

我在开发我想实现Facebook连接认证什么一个ASP.NET MVC的网站。鉴别部分工作正常,但如果我尝试检查权限用户给应用程序(无论是与 HasPermissions() IsAuthorized())我得到这个错误。

FacebookWebContext 得到正确初始化应用程序设置。而据我所知 signed_request 仅在画布上的应用程序可用,还是我错了?

如何才能检查权限在普通网站上的用户进行验证后?

在此先感谢!

编辑:
下面是是抛出的异常的详细信息:

  System.Diagnostics.Contracts .__ ContractsRuntime.ContractEx​​ception发生消息= precondition失败!string.IsNullOrEmpty(settings.AppId)来源= Facebook.Web堆栈跟踪:
       在System.Diagnostics.Contracts .__ ContractsRuntime.TriggerFailure(ContractFailureKind样,消息字符串,字符串userMessage,字符串conditionText,异常内)
       在System.Diagnostics.Contracts .__ ContractsRuntime.ReportFailure(ContractFailureKind样,消息字符串,字符串conditionText,异常内)
       在System.Diagnostics.Contracts .__ ContractsRuntime.Requires(布尔条件,消息字符串,字符串conditionText)
       在Facebook.Web.FacebookWebContext..ctor(IFacebookApplication设置,HttpContextBase的HttpContext)
       在Facebook.Web.FacebookWebContext..ctor()
       在Facebook.Web.FacebookWebContext.get_Current()
       在Facebook.Web.FacebookWebClient..ctor(字符串的accessToken)
       在Facebook.Web.FacebookWebContext.HasPermissions(字符串的accessToken,字符串的appid,Int64的userid,字符串[]的权限)
       在Facebook.Web.FacebookWebContext.IsAuthorized(字符串[]的权限)
       在Piedone.FacebookTest.IsAuthorized(字符串[]的权限)的InnerException:


解决方案

请一定要设置在web.config中Facebook的设置

 < configSections>
    <节TYPE =Facebook.FacebookConfigurationSection,Facebook的NAME =facebookSettingsallowLocation =真allowDefinition的=无处不在/>
< / configSections>< facebookSettings的appid ={} APP_IDappSecret ={} app_secret/>

该SDK需要知道应用ID和应用程序的秘密序,以提取的Facebook的Javascript SDK设置信息。

您也可能希望在源$ C ​​$ C检查出的样本文件夹中。

I have researched about the topic mentioned in the title. Solutions say (besides this one) that the "Precondition failed: !string.IsNullOrEmpty(settings.AppId)" exception thrown by FacebookWebContext.IsAuthorized() is caused by not setting the signed request, which can be got from the query string.

I'm developing an ASP.NET MVC website in what I would like to implement Facebook Connect authentication. The authentication part works fine, but if I try to check the permissions the user gave the app (either with HasPermissions() or IsAuthorized()) I get this error.

FacebookWebContext gets properly initialized with app settings. And as far as I know signed_request is only available in canvas apps, or am I wrong?

How can one check the permissions in an ordinary website after the user has authenticated?

Thanks in advance!

Edit: Here are the details of the exception that's thrown:

  System.Diagnostics.Contracts.__ContractsRuntime.ContractException occurred   Message=Precondition failed: !string.IsNullOrEmpty(settings.AppId)   Source=Facebook.Web   StackTrace:
       at System.Diagnostics.Contracts.__ContractsRuntime.TriggerFailure(ContractFailureKind kind, String message, String userMessage, String conditionText, Exception inner)
       at System.Diagnostics.Contracts.__ContractsRuntime.ReportFailure(ContractFailureKind kind, String message, String conditionText, Exception inner)
       at System.Diagnostics.Contracts.__ContractsRuntime.Requires(Boolean condition, String message, String conditionText)
       at Facebook.Web.FacebookWebContext..ctor(IFacebookApplication settings, HttpContextBase httpContext)
       at Facebook.Web.FacebookWebContext..ctor()
       at Facebook.Web.FacebookWebContext.get_Current()
       at Facebook.Web.FacebookWebClient..ctor(String accessToken)
       at Facebook.Web.FacebookWebContext.HasPermissions(String accessToken, String appId, Int64 userId, String[] permissions)
       at Facebook.Web.FacebookWebContext.IsAuthorized(String[] permissions)
       at Piedone.FacebookTest.IsAuthorized(String[] permissions)   InnerException:

解决方案

make sure to set the facebook settings in web.config

 <configSections>
    <section type="Facebook.FacebookConfigurationSection, Facebook" name="facebookSettings" allowLocation="true" allowDefinition="Everywhere" />
</configSections>

<facebookSettings appId = "{app_id}" appSecret = "{app_secret}"/>

The sdk needs to know the app id and app secret inorder to extract information set by the Facebook Javascript SDK.

You might also want to check out the "Samples" folder in the source code.

这篇关于Facebook的C#SDK签名的请求是空的IsAuthorized()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆