Search code examples
asp.net-coreauthenticationoauth-2.0google-identity

Google sign-in provider without ASP.NET Core Identity


Following the example from Microsoft at https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/social-without-identity?view=aspnetcore-6.0 for using the Google sign-in provider, I get an error stating that there is no DefaultSignInScheme.

This is however set in the AddAuthentication method, so I don't see what I'm missing.

The error occurs in the signin-google page after being redirected back to the webapplication from Google.

As far as I can see, I'm following the example to every detail.

enter image description here

enter image description here


Solution

  • Can modify the code like this?

    builder.Services.AddAuthentication(options =>
    {
        options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
    })
    .AddCookie()
    .AddGoogle(GoogleDefaults.AuthenticationScheme, options =>
    {
        options.ClientId = builder.Configuration["Authentication:Google:ClientId"];
        options.ClientSecret = builder.Configuration["Authentication:Google:ClientSecret"];
    });