zoukankan      html  css  js  c++  java
  • .net core facebook 容易进的一个坑

    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:\_xx_sso"));
                            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(); 否则无法跳转。

  • 相关阅读:
    洛谷P2158 [SDOI2008]仪仗队 欧拉函数的应用
    leetcode 130. 被围绕的区域 DFS
    TediousLee CodeForces
    AccurateLee双指针+贪心+字符串
    leetcode80. 删除排序数组中的重复项 II
    CHFDORA:哆啦 A 梦
    cdq分治浅谈
    leetcode面试题64. 求1+2+…+n
    leetcode84. 柱状图中最大的矩形
    leetcode874. 模拟行走机器人
  • 原文地址:https://www.cnblogs.com/wintersoft/p/10801302.html
Copyright © 2011-2022 走看看