SSO login in ASP.NET MVC web application can not open Microsoft page for login

Afi M 0 Reputation points

I am trying to add extra login with Microsoft to our project. I have created the app in Azure and did everything as the sample code that Azure provided for me, but when I press the login with Microsoft, it can not be redirected to Microsoft login page and it stays on the login page

Here is my startup code:

public class Startup
    string clientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"];

    string redirectUri = System.Configuration.ConfigurationManager.AppSettings["RedirectUri"];

    static string tenant = System.Configuration.ConfigurationManager.AppSettings["Tenant"];

    string authority = String.Format(System.Globalization.CultureInfo.InvariantCulture, System.Configuration.ConfigurationManager.AppSettings["Authority"], tenant);

    public void Configuration(IAppBuilder app)

      app.UseCookieAuthentication(new CookieAuthenticationOptions { });

            new OpenIdConnectAuthenticationOptions
               // AuthenticationMode = AuthenticationMode.Passive,
                ClientId = clientId,
                Authority = authority,
                RedirectUri = redirectUri,
                PostLogoutRedirectUri = redirectUri,
                Scope = OpenIdConnectScope.OpenIdProfile,
                ResponseType = OpenIdConnectResponseType.CodeIdToken,
                TokenValidationParameters = new TokenValidationParameters()
                    ValidateIssuer = false // This is a simplification
                Notifications = new OpenIdConnectAuthenticationNotifications
                    AuthenticationFailed = OnAuthenticationFailed

    private Task OnAuthenticationFailed(AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> context)
        context.Response.Redirect("/?errormessage=" + context.Exception.Message);
        return Task.FromResult(0);

I have tried the sample code from Azure . enter image description here and here is the part in web.config:

<add key="ClientId" value=" our app client id " />

<add key="Tenant" value="organizations" />

<add key="Authority"

value="{0}/v2.0" />

<add key="redirectUri" value="https://localhost:44300/"/>

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
17,484 questions
{count} votes