title: How to make [Authorize] trigger openId middleware
body: <p>I'm trying out some features of ASP.NET 5 and I'm struggling a bit with authentication. I've managed to use most of <a href="https://github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnect-aspnet5" rel="nofollow">this</a> sample app to connect to my Azure AD to log in, but I can't figure out how to restrict parts of my web app to authenticated users only. The article that accompanies the sample app I used states that </p>
  
  <blockquote>
    <p>You can trigger the middleware to send an OpenID Connect sign-in
    request by decorating a class or method with the [Authorize]
    attribute, or by issuing a challenge</p>
  </blockquote>
  
  <p>Since I'd like to avoid repeating the same challenge code everywhere, I opted for the attribute approach, but it doesn't work at all. All it seems to do is block access to unauthorized users, without redirecting to the login page the way the challenge does.</p>
  
  <p>Since I intended the app I am building to be more private than public, I've also tried creating a global policy and opening up some select features using the AllowAnonymous attribute. This works, but again the unauthorized pages are simply shown as blank, instead of a challenge being issued.</p>
  
  <p>This is the policy code I'm using currently, taken from <a href="http://www.rosengren.me/blog/global-authorization-attribute-filter-mvc6-vnext-aspnet5/" rel="nofollow">here</a>: </p>
  
  <pre><code>var policy = new AuthorizationPolicyBuilder()
              //This is what makes it function like the basic [Authorize] attribute
              .RequireAuthenticatedUser()
              .Build();
  
              services.Configure&lt;MvcOptions&gt;(options =&gt;
              {
                  options.Filters.Add(new AuthorizeFilter(policy));
              });
  </code></pre>
  
  <p>Am I missing some setup to the authorization attribute or the policy that issues the challenge?</p>