1

I'm setting up social login in an ASP.NET Core 2.0 application without using Identity.

I simply want to authenticate the user through Facebook, Google and LinkedIn and receive their info. I handle storing user info myself.

Here's what I've done so far which is giving me the following error:

No authentication handler is configured to handle the scheme: facebook

Here's the Startup.cs file changes:

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?}");
            });
        }

I then have this action method where I send the user to determine the provider we're using for authenticaiton e.g. Facebook, Google, etc. This code came from my ASP.NET Core 1.1 app which is working fine.

    [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;
    }

I'm getting the error message when I hit the ChallangeAsync line.

What am I doing wrong?

R. Richards
  • 24,603
  • 10
  • 64
  • 64
Sam
  • 26,817
  • 58
  • 206
  • 383

1 Answers1

1

No authentication handler is configured to handle the scheme: facebook

Scheme names are case-sensitive. Use provider=Facebook instead of provider=facebook and it should work.

Kévin Chalet
  • 39,509
  • 7
  • 121
  • 131
  • I'm also trying to add `LinkedIn` authentication. What would be the scheme for that? I tried `LinkedIn` but again, I'm getting the `no handler is configured` error. – Sam Aug 19 '17 at 23:06
  • Feel free to open a separate question (please post the link here). The answer is not complicated, but I'm sure many people will face similar issues at some point when migrating to 2.0. – Kévin Chalet Aug 19 '17 at 23:08
  • Good point! Here's the link to my new question: https://stackoverflow.com/questions/45777071/setting-up-linkedin-oauth-authentication-in-asp-net-core-2-0 – Sam Aug 19 '17 at 23:15