Microsoft Azure SSO doesn't sign me in

Viewed 153

I've been trying to solve this task for days now and the time has come to ask for help. I have a fully functioning test-project with Microsoft Azure SSO but it doesn't work when I use the code in my own project. The working project is using .net framework 4.7.2 and is based on this tutorial https://docs.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-asp-webapp . My own code is also using .net framework 4.7.2.

        public ActionResult Index()
    {
        return View();
    }

    public void SignIn()
    {
        if (!Request.IsAuthenticated)
        {
            HttpContext.GetOwinContext().Authentication.Challenge(
                new AuthenticationProperties { RedirectUri = "/" },
                OpenIdConnectAuthenticationDefaults.AuthenticationType);
        }
    }

The view returned from this method contains a button that looks like this:

        <a href="@Url.Action("SignIn", "SSO")" onclick=""style="text-decoration: none;">
        <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="300px" height="50px" viewBox="0 0 3278 522" class="SignInButton">
            <style type="text/css">
                .fil0:hover {
                    fill: #4B4B4B;
                }

                .fnt0 {
                    font-size: 260px;
                    font-family: 'Segoe UI Semibold', 'Segoe UI';
                    text-decoration: none;
                }
            </style>
            <rect class="fil0" x="2" y="2" width="3174" height="517" fill="black"/>
            <rect x="150" y="129" width="122" height="122" fill="#F35325"/>
            <rect x="284" y="129" width="122" height="122" fill="#81BC06"/>
            <rect x="150" y="263" width="122" height="122" fill="#05A6F0"/>
            <rect x="284" y="263" width="122" height="122" fill="#FFBA08"/>
            <text x="470" y="357" fill="white" class="fnt0">Sign in with Microsoft</text>
        </svg>
    </a>

This is all working fine until the SignIn-method is done, then the website sends me back to whatever loginurl I use.

<forms name="SSO" loginUrl="/sso/index" defaultUrl="~/Home/Index" slidingExpiration="true" protection="All" timeout="120" />

I can still get to the Microsoft login page by instead calling the SignIn-method from Index but that is sadly not a solution. My next problem is that when I get to the Microsoft login page(by calling SignIn from Index), it just sais "we couldn't sign you in. please try again." I have confirmed that cookies are being created by microsoft! The Request.IsAuthenticated is always false, which is not the case in the test-project. Please tell me what code I need to share for this problem to be solved.

0 Answers
Related