当前位置: 首页>>代码示例>>C#>>正文


C# FacebookClient.TryParseSignedRequest方法代码示例

本文整理汇总了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);
        }
开发者ID:riha,项目名称:spin2win,代码行数:57,代码来源:FacebookAuthModule.cs

示例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();
        }
开发者ID:fluffyclaret,项目名称:facebook-canvas-aspnet-sample,代码行数:63,代码来源:NinjectMVC3.cs


注:本文中的Facebook.FacebookClient.TryParseSignedRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。