First of all, make sure you correctly register your app in Azure Active Directory and that your code is providing all necessary details (HTTP code 401 means "Unauthorized"). If you need a help with it, please tell us what you have done, because we can't know it.
Also, try testing your code locally before deploying it to Azure.