The issue is that the default registration of an app in Azure AD requires the user click a button saying "I trust" this app. If you look at this video:
https://www.youtube.com/watch?v=ZSaBFf3ziUk
and go into the video about the 2:15 mark. This shows with simple app registration there is a one-time need for user interaction. After logging the first time with user interaction, your code can then authenticate programmatically without user interaction.
There is a way around this. It requires that you have an Azure subscription and that you use the Azure portal to register the app and configure security settings so that it doesn't require interactive consent on the part of the user.