title: Asp.net Identity using password and Azure Active Directory authentication
body: <p>I'm building an ASP.NET MVC 5 web site using Asp.net Identity (OWIN) and want to support both traditional username/password authentication as well as authentication against Azure Active Directory.  This app does not need to authenticate against Microsoft IDs (Live IDs), Facebook, Twitter or any of the other external providers.  The closest SO question I found is this one: <a href="https://stackoverflow.com/questions/29681302/how-to-do-both-azure-active-directory-single-sign-on-and-forms-authentications-o">How to do both Azure Active Directory Single Sign On and Forms Authentications on ASP.NET MVC</a></p>
  
  <p>I've looked at the samples that get created when you create a project using the "Individual User Accounts" option as well as the "Work and School Accounts" option in VS 2015.  I have authentication working well individually; it's only when I try to combine them that I'm running into problems.</p>
  
  <p>In my Startup_Auth.cs file, I am configuring OWIN like this:</p>
  
  <pre><code>    public void ConfigureAuth(IAppBuilder app)
      {
  
          app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
  
          //app.UseCookieAuthentication(new CookieAuthenticationOptions { });
  
          app.UseCookieAuthentication(new CookieAuthenticationOptions
          {
              AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
              LoginPath = new PathString("/account/sign-in")
          });
  
          app.UseOpenIdConnectAuthentication(
              new OpenIdConnectAuthenticationOptions
              {
                  ClientId = clientId,
                  Authority = authority,
                  TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters
                  {
                      ValidateIssuer = false,
                  },
                  Notifications = new OpenIdConnectAuthenticationNotifications()
                  {
                      SecurityTokenValidated = (context) =&gt; 
                      {
                          return Task.FromResult(0);
                      },
                      AuthorizationCodeReceived = (context) =&gt;
                      {
                          return Task.FromResult(0);
                      },
                      AuthenticationFailed = (context) =&gt;
                      {
                          context.OwinContext.Response.Redirect("/Home/Error");
                          context.HandleResponse(); // Suppress the exception
                          return Task.FromResult(0);
                      }
                  }
              }
          );
      }  
  </code></pre>
  
  <p>This configuration works for password authentication, but doesn't work for AAD authentication.  To enable AAD authentication I need to either comment out the line setting the AuthenticationType</p>
  
  <pre><code>AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
  </code></pre>
  
  <p>Or, just set CookieAuthentication with no values.</p>
  
  <pre><code>app.UseCookieAuthentication(new CookieAuthenticationOptions { });
  </code></pre>
  
  <p>I'd guess that there is a relatively simple approach to this and would appreciate some ideas on where to start looking.</p>