Comments (3)
I have added a new private class called FacebookWebHelper. Currently it is around 200 lines of code compared to thousand of line of Facebook.Web.dll and Facebook.Web.Mvc.dll.
Currently it is capable of parsing signed_request (both the oauth 2.0 signed_request cookie set by fb js sdk and the signed_request form value from canvas.)
There are two methods for parsing signed_request.
https://github.com/microsoft-dpe/facebook-csharp-sdk/commit/083ece31b81da663f4570c0331eb0ef696d6de50#L3R24
First method parses the signed_request string value.
https://github.com/microsoft-dpe/facebook-csharp-sdk/commit/083ece31b81da663f4570c0331eb0ef696d6de50#L3R66
Second method parses the signed_request value by looking at request.Forms["signed_request"](required by canvas app) and then request.Cookies["fbsr_appid"](required by fb js sdk). This method also caches the decoded signed_request per request, thus you will get performance benefits.
One huge advantage of FacebookWebHelper is it does not take any dependency on System.Web but rather uses Func<> so other projects like Nancy can easily consume it.
public static object TryParseFacebookSignedRequest(string appId, string appSecret, Func<bool> isInCache, Func<object> getFromCache, Func<string> getSignedRequestFormValue, Func<string, string> getSignedRequestCookieValue, Action<object> cache, Func<string, object> deserializeObject, bool throws)
Here is an example how Nancy could make use of FacebookWebHelper. (We can easily support System.Web by using HttpContext instead of NancyContext with some other minor changes.)
private static object TryParseFacebookSignedRequestInternal(NancyContext context, string appId, string appSecret, bool throws)
{
if (context == null)
throw new ArgumentNullException("context");
var request = context.Request;
var items = context.Items;
return FacebookWebHelper.TryParseFacebookSignedRequest(
appId, appSecret,
() => items.ContainsKey(SignedRequestKey),
() => items[SignedRequestKey] as IDictionary<string, object>,
() => request.Form.signed_request.HasValue ? request.Form.signed_request : string.Empty,
cookieName => request.Cookies.ContainsKey(cookieName) ? request.Cookies[cookieName] : string.Empty,
signedRequest => items[SignedRequestKey] = signedRequest,
DeserializeObject,
throws);
}
There is also FacebookCanvasPageUrl method which is capable of generating url for facebook canvas application.
https://github.com/microsoft-dpe/facebook-csharp-sdk/commit/083ece31b81da663f4570c0331eb0ef696d6de50#L3R101
Here is a sample for FacebookCanvasPageUrl in Nancy. this can again be easily ported to System.Web.dll
public static string FacebookCanvasPageUrl(this NancyContext context, string canvasPageOrAppName,
bool? https = null, bool? beta = null)
{
if (context == null)
throw new ArgumentNullException("context");
if (context.Request == null)
throw new ArgumentException("context.Request is null");
var request = context.Request;
return FacebookWebHelper.FacebookCanvasPageUrl(canvasPageOrAppName,
() => request.Url.Scheme,
() => request.Headers != null && !string.IsNullOrEmpty(request.Headers.Referrer) && new Uri(request.Headers.Referrer).Host == "apps.beta.facebook.com",
https,
beta);
}
we can now call the method in the following manner: (assume I have added FacebookCanvasPageUrl as an extension method for HttpContextBase in for mvc)
var url = HttpContext.FacebookCanvasPageUrl("appname"); // https://apps.facebook.com/appname
// assume FacebookApplication.Current.CanvasPage = http://apps.facebook.com/appname
url = HttpContext.FacebookCanvasePageUrl(FacebookApplication.Current); // https://apps.facebok.com/appname
url = HttpContext.FacebookCanvasPageUrl("appname", https: false, beta: true); // http://apps.beta.facebook.com/appname
You can either pass only the appname or the full canvas page url from IFacebookApplication. You can also explicitly set https or beta. If it is null, it will look at the request and try to figure it out by itself.
Though FacebookWebHelper is small, it has huge advantage and can accomplish quite a lot.
I will be adding FacebookTabUrl() and FacebookPageUrl() in the future.
from facebook-csharp-sdk.
source is still there but the project references from the solution has been removed.
from facebook-csharp-sdk.
removing in v6.
will instead provide samples
from facebook-csharp-sdk.
Related Issues (20)
- Update links to docs accordingly
- Error On Video Upload To Page
- Which graph version APIs we are using for facebook UWP nuget package? HOT 3
- SDK support? HOT 3
- Assembly version number is not getting updated with versions
- Facebook is deprecating publish_actions persmission, can we still use this SDK?
- unkown facebook response
- System.Exception: Unknown Error Occured --> System.UriFormatException: Invalid URI: The Uri string is too long HOT 2
- Get Page Post Picture
- Could not install package 'Facebook 7.0.6' HOT 1
- Video caption - language spec. character became "?"
- Depracted facebook web sdk..?
- Add support for Graph API v3.2?
- Image posts with text message do not post the message HOT 2
- Your homepage has links to Casinos?
- A general query
- Is this project dead? HOT 1
- Where can I find connected pages?
- Moving to the new .NET Foundation CLA service HOT 1
- .Net Core 8.0 Feature Request
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facebook-csharp-sdk.