title: MVC to Azure Active Directory sign on replying with "Bad Request" and message with "Unable to create to obtain configuration from"
body: <p>What am I doing wrong?  </p>
  
  <p>I'm trying to sign on to an Azure Active Directory from a sample MVC app and getting "Bad Request". </p>
  
  <p>I'm following the example (dated 7/17/2015) here:</p>
  
  <p><a href="https://azure.microsoft.com/en-us/documentation/articles/active-directory-devquickstarts-webapp-dotnet/" rel="nofollow">azure.microsoft.com example</a></p>
  
  <p>and here is a more detailed step by step of the same data by someone else:</p>
  
  <p><a href="http://developers.de/blogs/damir_dobric/archive/2014/08/03/protect-you-web-application-with-multifactor-authentication-and-azure-active-directory.aspx" rel="nofollow">azure example expanded by blogger</a></p>
  
  <p>I've replaced the name of my active directory with "myActiveDirectory" below.</p>
  
  <p>Here is my webconfig data:</p>
  
  <pre><code>&lt;add key="ida:AppKey" value="&lt;snip my key&gt;" /&gt;
  &lt;add key="ida:ClientId" value="d2bfc007-&lt;snip my client ID&gt;-9f" /&gt;
  &lt;add key="ida:Tenant" value="myActiveDirectory.onmicrosoft.com" /&gt;
  &lt;add key="ida:AADInstance" value="https://login.windows.net/{0}" /&gt;
  &lt;add key="ida:PostLogoutRedirectUri" value="https://localhost:44320/" /&gt;
  </code></pre>
  
  <p>AccountController.cs</p>
  
  <pre><code>using System.Web;
  using System.Web.Mvc;
  // OWIN 
  using Microsoft.Owin.Security;
  using Microsoft.Owin.Security.OpenIdConnect;
  using Microsoft.Owin.Security.Cookies;
  
  
  namespace TodoListWebApp.Controllers
  {
      public class AccountController : Controller
      {
          public void SignIn()
          {
              // Sends an OpenID sign-in request. 
              if (!Request.IsAuthenticated)
              {
                  HttpContext.GetOwinContext().
                  Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" },
                  OpenIdConnectAuthenticationDefaults.AuthenticationType);
              }
          }
  
  
          public void SignOut()
          {
              // Sends an OpenID sign-out request. 
              HttpContext.GetOwinContext().Authentication.SignOut(
                  OpenIdConnectAuthenticationDefaults.AuthenticationType,
                  CookieAuthenticationDefaults.AuthenticationType);
          }
      }
  }
  </code></pre>
  
  <p>Startup.cs</p>
  
  <pre><code>// OWIN 
  using Owin;
  
  namespace ActiveDirSample
  {
      public partial class Startup
      {
          public void Configuration(IAppBuilder app)
          {
              ConfigureAuth(app);
          }
      }
  }
  </code></pre>
  
  <p>Startup.Auth.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Configuration;
  
  
  // OWIN 
  using Owin;
  using Microsoft.Owin;
  using Microsoft.Owin.Security;
  using Microsoft.Owin.Security.OpenIdConnect;
  using Microsoft.Owin.Security.Cookies;
  using System.Globalization;
  
  
  [assembly: OwinStartup(typeof(ActiveDirSample.Startup))]
  
  namespace ActiveDirSample
  {
  
  
  
    public partial class Startup
      {
  
          private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
          private static string appKey = ConfigurationManager.AppSettings["ida:AppKey"];
          private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
          private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
          private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];
  
          string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
  
          public void ConfigureAuth(IAppBuilder app)
          {
              app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
  
              app.UseCookieAuthentication(new CookieAuthenticationOptions());
  
              app.UseOpenIdConnectAuthentication(
                  new OpenIdConnectAuthenticationOptions
                  {
                      ClientId = clientId,
                      Authority = authority,
                      PostLogoutRedirectUri = postLogoutRedirectUri,
                  });
          }
      }
  }
  </code></pre>
  
  <p>Here is the response I get:</p>
  
  <hr>
  
  <pre><code>Server Error in '/' Application.
  
  Response status code does not indicate success: 400 (Bad Request). 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
   Exception Details: System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
  
  Source Error: 
  
  
   An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
  
  Stack Trace: 
  
  
  
  [HttpRequestException: Response status code does not indicate success: 400 (Bad Request).]
     System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() +92108
     Microsoft.IdentityModel.Protocols.&lt;GetDocumentAsync&gt;d__0.MoveNext() in c:\workspace\WilsonForDotNet45Release\src\Microsoft.IdentityModel.Protocol.Extensions\Configuration\HttpDocumentRetriever.cs:54
  
  [IOException: Unable to get document from: https://login.windows.net/myActiveDirectory.onmicrosoft.com/.well-known/openid-configuration]
     Microsoft.IdentityModel.Protocols.&lt;GetDocumentAsync&gt;d__0.MoveNext() in c:\workspace\WilsonForDotNet45Release\src\Microsoft.IdentityModel.Protocol.Extensions\Configuration\HttpDocumentRetriever.cs:59
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.IdentityModel.Protocols.&lt;GetAsync&gt;d__0.MoveNext() in c:\workspace\WilsonForDotNet45Release\src\Microsoft.IdentityModel.Protocol.Extensions\Configuration\OpenIdConnectConfigurationRetriever.cs:81
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +25
     Microsoft.IdentityModel.Protocols.&lt;GetConfigurationAsync&gt;d__3.MoveNext() in c:\workspace\WilsonForDotNet45Release\src\Microsoft.IdentityModel.Protocol.Extensions\Configuration\ConfigurationManager.cs:198
  
  [InvalidOperationException: IDX10803: Unable to create to obtain configuration from: 'https://login.windows.net/myActiveDirectory.onmicrosoft.com/.well-known/openid-configuration'.]
     Microsoft.IdentityModel.Protocols.&lt;GetConfigurationAsync&gt;d__3.MoveNext() in c:\workspace\WilsonForDotNet45Release\src\Microsoft.IdentityModel.Protocol.Extensions\Configuration\ConfigurationManager.cs:212
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.Owin.Security.OpenIdConnect.&lt;ApplyResponseChallengeAsync&gt;d__c.MoveNext() +599
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.Owin.Security.Infrastructure.&lt;ApplyResponseCoreAsync&gt;d__b.MoveNext() +292
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.Owin.Security.Infrastructure.&lt;ApplyResponseAsync&gt;d__8.MoveNext() +278
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.Owin.Security.Infrastructure.&lt;TeardownAsync&gt;d__5.MoveNext() +165
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.Owin.Security.Infrastructure.&lt;Invoke&gt;d__0.MoveNext() +716
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.&lt;RunApp&gt;d__5.MoveNext() +187
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.Owin.Security.Infrastructure.&lt;Invoke&gt;d__0.MoveNext() +561
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.&lt;RunApp&gt;d__5.MoveNext() +187
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.&lt;DoFinalWork&gt;d__2.MoveNext() +185
     Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +69
     Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) +64
     System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +380
     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155
  
  
  
  
  Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.81.0 
  </code></pre>
  
  <hr>