问题
The question says it all:
How can I get an access token to use on graph api calls from a asp.net webforms 4.0 iframe canvas app.
My canvas application has been configured to enable the OAuth 2.0 for Canvas (beta) among other things.
This means I am getting the signed_request
parameter on my iframe which I am successfully reading.
From the oficial documentation on canvas authentication
The signed_request parameter is the concatenation of a HMAC SHA-256 signature string, a period (.), and a base64url encoded JSON object.
There is a php code in the documentation which decodes the signed_request
but I haven't been able to implement it propertly in C# partly beacuse to be honest I prefer not to reinvet the wheel but to use someone else code that has been already tested.
This is where my quest for a good C# Facebook SDK started again (since facebook changes everything every few months librarys get usually obsolete).
I have used the codeplex's Facebook Developer Toolkit in the past but it seems to be getting outdated ans the lastest stable release is very old (in facebook API time)
Some months ago used the Oficial Facebook C# SDK from GitHub but it lacks completly the authentication support.
Now I have found on Nuget and really liked the Facebook C# SDK from Nathan Totten who is one of the top Facebook Experts here in StackOverflow.
If you Nathan read this (or anyone that also uses this sdk), how can I use this SDK to get an access token to use in my canvas app.
Anyway if there is a better way to get a token, maybe with the Javascript library please let me ( and the people who wonder the same as me ) know.
回答1:
Hey, Carlos. So to get the access token, you just need to do the following after the user has authenticated:
FacebookApp app = new FacebookApp();
var accessToken = app.Session.AccessToken;
Also, see my answer to this question: facebook-C#-sdk MVC "Hello World" app - how to get access token?
Hopefully that helps, otherwise let me know if you have any other questions.
来源:https://stackoverflow.com/questions/4226852/get-oauth-2-0-access-token-from-asp-net-webforms-iframe-canvas-application