首页 > Web开发 > 详细

.net core facebook 容易进的一个坑

时间:2019-05-02 01:00:05      阅读:324      评论:0      收藏:0      [点我收藏+]

Microsoft.AspNetCore.Authentication.Facebook 库

 

                services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
                    .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
                    {
                        options.DataProtectionProvider = CreateRedisDataProtectionProvider(ConnectionMultiplexer.Connect($"{redisConnectionString},defaultDataBase=1"));
                        //options.DataProtectionProvider = DataProtectionProvider.Create(new DirectoryInfo(@"C:\_surveysso"));
                        options.SlidingExpiration = true;
                        options.LoginPath = "/Account/SignIn";
                        options.Cookie = new CookieBuilder()
                        {
                            HttpOnly = true,
                            Name = $".{GetType().Namespace}",
                        };
                    })
                    .AddFacebook(FacebookDefaults.AuthenticationScheme, o =>
                     {
                         o.AppId = Configuration.GetSection("FacebookDeveloper").GetValue<string>("AppId");
                         o.AppSecret = Configuration.GetSection("FacebookDeveloper").GetValue<string>("AppSecret");
                         o.SaveTokens = false;
                         o.CallbackPath = new PathString("/signin-facebook");
                         o.Events = new Microsoft.AspNetCore.Authentication.OAuth.OAuthEvents
                         {
                             OnRemoteFailure = context =>
                             {
                                 if(context.Request.Query["error"] == "access_denied" && context.Request.Query["error_code"] == "200" && context.Request.Query["error_description"] == "Permissions+error" && context.Request.Query["error_reason"] == "user_denied")
                                    context.Response.Redirect("/Account/SignIn");
                                 else
                                    context.Response.Redirect("/Profile");
                                 context.HandleResponse();
                                 return Task.CompletedTask;
                             }
                         };
                     });

 

必须要有 context.HandleResponse(); 否则无法跳转。

.net core facebook 容易进的一个坑

原文:https://www.cnblogs.com/wintersoft/p/10801302.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!