我正在使用Facebook C#SDK。这是基于ASPNet-MVC3-JsSdk示例的MOSTLY。在我的应用程序中,我有标准的Javascript代码(大部分直接从示例应用程序中获取)。
function facebooklogin() {
FB.login(function (response) {
if (response.authResponse) {
alert(window.location.pathname);
// user authorized
window.location = window.location.origin + "/Account/FacebookLogon" + "?returnUrl=" + window.location.pathname;
} else {
// user cancelled
}
}, { scope: "@ScoreTrack.Controllers.AccountController.ExtendedPermissions"});
};
我基本上想要重定向到我的Account.FacebookLogon()
控制器操作,在那里我检查授权,如果用户授权了应用程序,那么我设置了FormsAuthentication cookie / token。
public ActionResult FacebookLogon(string returnURL)
{
var fbWebContext = new FacebookWebContext(FacebookApplication.Current, ControllerContext.HttpContext); // or FacebookWebContext.Current;
if (fbWebContext.IsAuthorized(@MyApp.Controllers.AccountController.ExtendedPermissions.Split(',')))
{
// If the User is Logged in and Authorized
var fbwc = new FacebookWebClient();
dynamic me = fbwc.Get("me");
FormsAuthenticationTicket authTicket = new
FormsAuthenticationTicket(1, //version
me.username, // user name
DateTime.Now, //creation
DateTime.Now.AddMinutes(30), //Expiration
false, //Persistent
me.username);
string encTicket = FormsAuthentication.Encrypt(authTicket);
this.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
}
return Redirect(Url.Content("~/" + returnURL));
}
一切都很有效,直到某一点:
我点击我的Facebook登录按钮......
AccountController.FacebookLogon()
方法FacebookLogon()
方法检查Facebook是否已获得授权,C#SDK表示不是。互联网怎么样?还是FacebookC#SDK人?或其他聪明的Facebook C#程序员帅哥?
到底是什么?
任何?