.net core facebook 容易進的一個坑
阿新 • • 發佈:2019-05-02
type() ted error tor etsec events cal direct cookie
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 容易進的一個坑