5

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://learn.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

1 Answer 1

1

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";

    // ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

Does it use cookie-based authentication under the hood? I mean, once user gets validated, how the state is persisted in MVC application? Though, I looked into the code but did not find any implementation for this Context.SignInAsync() for Microsoft auth scheme.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.