title: Authentication for Azure Functions
body: <p>I've spent the past 24 hours reading all about how to create Azure Functions and have successfully converted a MVC WebApi over to a new Function App with multiple functions. My problem is that I've not found any clear documentation or tutorials on how to do the most basic of authentication with them. </p>
  
  <p>My scenario is pretty straight forward. Provision users in my AAD, then grant those users access to specific functions. Users on a website will click on UI elements that in turn trigger Javascript that calls my Azure Functions. In the function I need to be able to verify their identity somehow as I'll be passing that along to other functions that interact with a SQL instance. </p>
  
  <p>Can someone please point me at docs, articles, an example, something, that shows how I can achieve this? </p>
  
  <p>For the record I've found in the portal the "Authentication" config for my Function App and have chosen AAD as my Authentication Provider. I've added my Function App to it and have provisioned a few users. I've then wrote the following test function:</p>
  
  <pre><code>[FunctionName("GetThings")]
  public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.User, "GET", Route = null)]HttpRequestMessage req, TraceWriter log)
  {
      log.Info("Getting all the things");
      var identity = ClaimsPrincipal.Current.Identity;
  
      return identity.IsAuthenticated ?
          req.CreateResponse(HttpStatusCode.Unauthorized, "Not authenticated!") :
          req.CreateResponse(HttpStatusCode.OK, $"Hi {identity.Name}!");
  }
  </code></pre>
  
  <p>Currently when trying to hit the endpoint directly I get redirected to a login page... so I guess that part is working. How I generate / retrieve user tokens, send them along on the request to the functions, or process them on the server isn't clear to me though. </p>
  
  <p>Help?</p>