Anna Forrest
Anna Forrest

Reputation: 1741

Kentor/Owin/Azure AD Authentication

I have a web forms app which I am trying to authenticate against Azure AD using SAML 2/Kentor/Owin. I think I have things configured OK, but when my login page issues the following command I am not being redirected to a login page.

                    HttpContext.Current.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/Login.aspx" });

Here is my startup.cs

private void ConfigureSAML2Authentication(IAppBuilder app) {
        var authServicesOptions = new KentorAuthServicesAuthenticationOptions(false)
        {
            SPOptions = new SPOptions
            {
                EntityId = new EntityId("https://login.microsoftonline.com/<tenant guid>/saml2")
            }
            },
            AuthenticationType = "KentorAuthServices",
            Caption = "ADFS - SAML2p",
        }; 

        authServicesOptions.IdentityProviders.Add(new IdentityProvider(
            new EntityId("https://sts.windows.net/<tenant guid>/"),
            authServicesOptions.SPOptions)
        {
            MetadataLocation = "https://login.microsoftonline.com/<tenant guid>/federationmetadata/2007-06/federationmetadata.xml",
            LoadMetadata = true,
        });

        app.UseKentorAuthServicesAuthentication(authServicesOptions);
    } 

As far as I can tell looking at the Network Tools in chrome, no auth request is being sent at all. Is anyone able to tell me why?

Upvotes: 2

Views: 509

Answers (1)

Steve P
Steve P

Reputation: 19377

The AuthServices middleware is configured as Passive by default, so it will not automatically respond to an authentication challenge unless you specify the provider.

When you issue the challenge you should specify the same AuthenticationType that you used when the middleware was set up. By default this is "KentorAuthServices" but can be changed.

If you change your challenge to include the type, it should trigger the redirect:

HttpContext.Current.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/Login.aspx" }, "KentorAuthServices");

Upvotes: 2

Related Questions