2
votes

I'm setting up a social sign-in provider authentication without ASP.NET Core Identity with a Microsoft authentication. The linked tutorial uses Google as an example and provides the code to get its authentication scheme for the DefaultChallengeScheme.

What is the authentication scheme for Microsoft? I've been unable to find it.

My Startup.cs > ConfigureServices method:

public void ConfigureServices(IServiceCollection services)
{
    //set up using this tutorial https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/social-without-identity?view=aspnetcore-2.2
    services
        .AddAuthentication(authenticationOptions =>
        {
            authenticationOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            authenticationOptions.DefaultChallengeScheme = //??? what goes here
        })
        .AddCookie()
        .AddMicrosoftAccount(microsoftOptions =>
        {
            microsoftOptions.ClientId = Configuration["Authentication:Microsoft:ClientId"];
            microsoftOptions.ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"];
        });

    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
1
Most likely possibility: authenticationOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; See docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/… - Robert Harvey

1 Answers

1
votes

The literal value used for the authentication scheme is Microsoft. You can access this value using the constant MicrosoftAccountDefaults.AuthenticationScheme:

authenticationOptions.DefaultChallengeScheme = 
    MicrosoftAccountDefaults.AuthenticationScheme;

Here's the source for the constant:

public static class MicrosoftAccountDefaults
{
    public const string AuthenticationScheme = "Microsoft";

    // ...
}