代码之家  ›  专栏  ›  技术社区  ›  Sam

在ASP中设置社会身份验证。NET Core 2.0

  •  1
  • Sam  · 技术社区  · 9 年前

    我正在ASP中设置社交登录。不使用标识的NET Core 2.0应用程序。

    以下是我迄今为止所做的工作,这给了我以下错误:

    没有配置任何身份验证处理程序来处理该方案:facebook

    public void ConfigureServices(IServiceCollection services)
            {
                services.AddMvc();
    
                // Added these lines for cookie and Facebook authentication
                services.AddAuthentication("MyCookieAuthenticationScheme")
                    .AddCookie(options => {
                        options.AccessDeniedPath = "/Account/Forbidden/";
                        options.LoginPath = "/Account/Login/";
                    })
                    .AddFacebook(facebookOptions =>
                    {
                        facebookOptions.AppId = "1234567890";
                        facebookOptions.AppSecret = "1234567890";
                    });
            }
    
            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                    app.UseBrowserLink();
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error");
                }
    
                app.UseStaticFiles();
    
                // Added this line
                app.UseAuthentication();
    
                app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "default",
                        template: "{controller=Home}/{action=Index}/{id?}");
                });
            }
    

    然后我有了这个动作方法,我发送用户来确定我们用于身份验证的提供商,例如脸书、谷歌等。这些代码来自我的ASP。NET Core 1.1应用程序运行良好。

        [AllowAnonymous]
        public async Task ExternalLogin(string provider, string returnUrl)
        {
            var properties = new AuthenticationProperties
            {
                RedirectUri = "Login/Callback"
            };
    
            // Add returnUrl to properties -- if applicable
            if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                properties.Items.Add("returnUrl", returnUrl);
    
            // The ASP.NET Core 1.1 version of this line was
            // await HttpContext.Authentication.ChallengeAsync(provider, properties);
            await HttpContext.ChallengeAsync(provider, properties);
    
            return;
        }
    

    当我点击 ChallangeAsync

    我做错了什么?

    1 回复  |  直到 9 年前
        1
  •  1
  •   Kévin Chalet    9 年前

    没有配置任何身份验证处理程序来处理该方案:facebook

    provider=Facebook 而不是 provider=facebook

    推荐文章