title: Microsoft OAuth2 return error=access_denied
body: <p>I'm trying using OAuth2 on my MVC 5 web app but I'm getting trouble with OAuth2 from Microsoft. When I signed on using Microsoft it returned error=access_denied. Below are my configurations: </p>
  
  <ol>
  <li><p>Set up public key, secret key and password <a href="http://apps.dev.microsoft.com/" rel="nofollow noreferrer">http://apps.dev.microsoft.com/</a> . (You must create key pair and password)</p></li>
  <li><p>Set up return Url <a href="https://localhost:44300/sign-microsoft" rel="nofollow noreferrer">https://localhost:44300/sign-microsoft</a></p></li>
  <li><p>Add these key pair which are application Id and secret key to Startup.Auth.cs</p></li>
  </ol>
  
  <blockquote>
  <pre><code>app.UseMicrosoftAccountAuthentication(
  new MicrosoftAccountAuthenticationOptions()
  {
    ClientId = "xxxx",
    ClientSecret = "xxx",
    Scope = { "wl.basic", "wl.emails" }
  });
  </code></pre>
  </blockquote>
  
  <ol start="4">
  <li>Below is action</li>
  </ol>
  
  <blockquote>
  <pre><code>[HttpPost]
  [AllowAnonymous]
  [ValidateAntiForgeryToken]
  public ActionResult ExternalLogin(string provider, string returnUrl)
  {
    if (provider.Equals("Microsoft"))
        returnUrl = "https://localhost:44300/signin-microsoft";
    // Request a redirect to the external login provider
    return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl =
  </code></pre>
    
    <p>returnUrl }));
        }</p>
  </blockquote>
  
  <p>I've looked around someone got trouble and solved by using https. I have spent several days but I can't find out the problem. </p>