How can I change the Microsoft Login?

Viewed 40

I was tasked that for my web page the users enter with Microsoft accounts, so when creating my project, I made an authentication with the Microsoft identity platform, but what this does is that as soon as I enter the web page (testing or production) it shows me the log in with Microsoft.

What I need is for it to first show me a "Login" view and for it to have a button that says "Sign in with a Microsoft account".

My question is, how can I change the default settings that Visual Studio gave me when using Microsoft authentication?

I don´t know what to change and I don't want to break my project, so I wanted to ask you first.

This is my Program.cs

using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.UI;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));

builder.Services.AddAuthorization(options =>

{
    options.FallbackPolicy = options.DefaultPolicy;
});

builder.Services.AddControllersWithViews(options =>
{
    var policy = new AuthorizationPolicyBuilder()
        .RequireAuthenticatedUser()
        .Build();
    options.Filters.Add(new AuthorizeFilter(policy));
});
builder.Services.AddRazorPages()
    .AddMicrosoftIdentityUI();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapRazorPages();
app.MapControllers();

app.Run();

This is How is starting:

enter image description here

How I'm trying to start:

                <form id="form_login" action="~/Home/LoginMicrosoft" method="post">
                    <div class="input">
                        <input  value="Use Microsoft account"/>
                        <span id="ver_clave" class="ver_clave input-group-append">
                            <i class="fa-brands fa-microsoft"></i>
                        </span>
                    </div>
                </form>

I don´t know what to show you so everything you need just let me know

I tried creating a Login View (like code before), and in controller when the form is submited, go to LoginMicrosoft and this is the code I have:

 [HttpPost]
        public async Task<IActionResult> LoginMicrosoft ()
        {
            try
            {
                MicrosoftAuthService aut = new MicrosoftAuthService();
                aut.Initialize();
                await aut.OnSignInAsync();

                return View("Index");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
0 Answers
Related