Facebook C# SDK signed request is null in IsAuthorized()

走远了吗. 提交于 2020-01-16 04:00:32

问题


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:

回答1:


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.



来源:https://stackoverflow.com/questions/7349362/facebook-c-sharp-sdk-signed-request-is-null-in-isauthorized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!