private void context_AuthenticateRequest(object sender, EventArgs e)
{
var httpApplication = (HttpApplication)sender;
var context = httpApplication.Context;
foreach (var regex in ExcludePathsRegEx)
{
if(new Regex(regex).IsMatch(context.Request.Path))
return;
}
var applicationId = ConfigurationManager.AppSettings["facebookApplicationId"];
var applicationSecret = ConfigurationManager.AppSettings["facebookApplicationSecret"];
var client = new FacebookClient();
//Read the signed request added by the Javascript SDK login
var signedRequestCookie = context.Request.Cookies[string.Concat("fbsr_", applicationId)];
dynamic signedRequest;
if (signedRequestCookie == null)
return;
if (!client.TryParseSignedRequest(applicationSecret, signedRequestCookie.Value, out signedRequest))
return;
if (signedRequest == null)
return;
if (signedRequest.expires != null)
{
int expires = signedRequest.expires;
return;
}
string userId = signedRequest.user_id;
if (string.IsNullOrEmpty(userId))
return;
User user;
try
{
user = User.Load(client, userId);
if (user == null)
return;
}
catch (FacebookOAuthException ex)
{
return;
}
context.User = new GenericPrincipal(user, null);
}