本文整理汇总了C#中Facebook.FacebookClient.TryParseSignedRequest方法的典型用法代码示例。如果您正苦于以下问题:C# FacebookClient.TryParseSignedRequest方法的具体用法?C# FacebookClient.TryParseSignedRequest怎么用?C# FacebookClient.TryParseSignedRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook.FacebookClient
的用法示例。
在下文中一共展示了FacebookClient.TryParseSignedRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: context_AuthenticateRequest
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);
}
示例2: RegisterFacebookServices
private static void RegisterFacebookServices(IKernel kernel)
{
kernel.Bind<IMyFacebookAppSettings>()
.ToConstant(new MyFacebookAppSettings
{
AppId = ""
AppSecret = ""
CanvasPageName = "" /* only the canvas page name and not the full url */
CanvasUrl = "http://localhost:2408/",
SecureCanvasUrl = "https://localhost:44300/"
})
.InSingletonScope();
kernel.Bind<IMyFacebookCanvasContext>()
.ToMethod(
ctx =>
{
var fb = new FacebookClient();
var request = HttpContext.Current.Request;
if (request.UrlReferrer != null)
{
fb.IsSecureConnection = request.UrlReferrer.Scheme == "https";
fb.UseFacebookBeta = request.UrlReferrer.Host == "apps.beta.facebook.com";
}
var canvasContext = new MyFacebookCanvasContext
{
AppSettings = ctx.Kernel.Get<IMyFacebookAppSettings>(),
FacebookClient = fb
};
object signedRequest;
if (fb.TryParseSignedRequest(canvasContext.AppSettings.AppSecret, HttpContext.Current.Request["signed_request"], out signedRequest))
{
canvasContext.SignedRequest = new MyFacebookSignedRequest(signedRequest);
if (!string.IsNullOrWhiteSpace(canvasContext.SignedRequest.AccessToken))
{
fb.AccessToken = canvasContext.SignedRequest.AccessToken;
try
{
dynamic result = fb.Get("me/permissions");
canvasContext.Permissions = result.data[0].Keys as IEnumerable<string>;
}
catch (FacebookOAuthException)
{
// log exception
// oauth token expired or invalid
canvasContext.SignedRequest = null;
fb.AccessToken = null;
}
}
}
return canvasContext;
})
.InRequestScope();
kernel.Bind<FacebookClient>()
.ToMethod(ctx => ctx.Kernel.Get<IMyFacebookCanvasContext>().FacebookClient)
.InRequestScope();
}