public static async Task <HttpResponseMessage> Run(HttpRequestMessage req,
                                                           [HttpTrigger(AuthorizationLevel.User, "post", Route = null)] POCOOrder order, TraceWriter log)
        {
            ClaimsPrincipal claimsPrincipal;
            CustomValidator customValidator = new CustomValidator(log);

            if ((claimsPrincipal = customValidator.ValidateToken(req.Headers.Authorization)) == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content = new StringContent("Invalid Token!", Encoding.UTF8, "application/json")
                });
            }

            string[] allowedRoles = GetEnvironmentVariable("AllowedRoles").Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            if (customValidator.IsInRole(claimsPrincipal, allowedRoles) == false)
            {
                return(new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content = new StringContent("Invalid Roles!", Encoding.UTF8, "application/json")
                });
            }

            string msg = $"Hello " + order.CustomerName + "! Your order for " + order.ProductName + " with quantity of " + order.OrderCount + " has been received. You will receive email at " + order.CustomerEmail + " as soon as order is shipped.";

            log.Info(msg);

            var connectionString = GetEnvironmentVariable("AzureWebJobsStorage");

            // Retrieve storage account from connection string.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            // Create the queue client.
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            // Retrieve a reference to a container.
            CloudQueue queue = queueClient.GetQueueReference("orderqueue");

            // Create the queue if it doesn't already exist
            queue.CreateIfNotExists();

            // Serialize POCO Order
            var orderData = JsonConvert.SerializeObject(order, Formatting.Indented);

            // Create a message and add it to the queue.
            CloudQueueMessage message = new CloudQueueMessage(orderData);

            queue.AddMessage(message);

            // Send an acknowledgement to client app
            return(await Task.Run(() =>
            {
                return new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(msg, Formatting.Indented), Encoding.UTF8, "application/json")
                };
            }));
        }