title: Azure Function with AD auth results in 401 Unauthorized when using Bearer tokens
body: <p>I have a very simple Azure function in C# for which I've setup Azure AD Auth. I've just used the Express settings to create an App registration in the Function configuration.</p>
  
  <pre><code>public static class IsAuthenticated
  {
      [FunctionName("IsAuthenticated")]
      public static async Task&lt;IActionResult&gt; Run(
          [HttpTrigger(AuthorizationLevel.Anonymous, "get", "options", Route = null)]
          HttpRequest req,
          ILogger log)
      {
          return new OkObjectResult("You are " + req.HttpContext.User.Identity.Name);
      }
  }
  </code></pre>
  
  <p>When I access the function in my browser everything works as expected (if not logged in I have to login and get redirected to my API). But if I try to access my function anywhere a Bearer token is needed I get an <code>401 Unauthorized</code> error. Even weirder I also can't execute the function in the Azure Portal.</p>
  
  <p><img src="https://i.stack.imgur.com/lkt4B.jpg" width="400" /></p>
  
  <p>But the token was aquired without a problem and added to the request:</p>
  
  <p><a href="https://i.stack.imgur.com/47wyO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/47wyO.png" alt="enter image description here"></a></p>
  
  <p>I've tried a few different things to solve this problem. First I thought maybe it's a CORS problem (since I've also had a few of those) and just set CORS to accept *, but nothing changed.</p>
  
  <p>Then I've added my API login endpoints to the redirect and tried setting the implicit grant to also accept Access tokens, it's still not working.</p>
  
  <p><a href="https://i.stack.imgur.com/t47nJ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/t47nJ.png" alt="enter image description here"></a></p>
  
  <p>Is there anything I've overlooked? Shouldn't the App registration express config just work with azure functions?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Putting the URL to my function app in the redirects as suggested by <a href="https://stackoverflow.com/a/55227490/503059">@thomas-schreiter</a> didn't change anything (I've tried the config in the screenshot and also just putting each of those values on it's own).</p>
  
  <p><a href="https://i.stack.imgur.com/gwesd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gwesd.png" alt="enter image description here"></a></p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>I've now also tried to aquire an Bearer token the manual way <a href="https://blogs.msdn.microsoft.com/aaddevsup/2018/05/23/using-postman-to-call-the-microsoft-graph-api-using-authorization-code-flow/" rel="noreferrer">with Postman</a>, but I still run into a 401 when calling my API.</p>