You're dealing with it the wrong way, so it will not work for you.
What you should do in summary is:
Register your app in the Azure active directory
Use the secrets of the App to start the authentication flow
when that is ready you can take several approximations one of them \
generate a URL for authentication, which the user or your app can do to launch the browser
once in the browser the user receives a verification code
the user enters the code in the console, you must use your program to receive that code
with that code you end the flow of authentication
It is not so trivial to do but it is not so complex either, but if it is the first time that you face this issue it can be quite cumbersome.
More info here even though it is with the first version of Azure Active Directory, but the flow is still basically the same even if the interface has changed.
link
I also recommend using ADAL .