title: I have an azure functions that connect to exchange web service unfortunately the service account used has MFA enabled
body: <p>I am looking for a solution without interactive login, but all the solutions I've found so far have it. Could someone point out how to get an access token for an MFA enabled account without using the interactive approach?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>string clientId = "CLIENTID";
  string tenantID = "TENANTID";
  
  string authority = $"https://login.microsoftonline.com/{tenantID}";
  string[] scopes = new string[] { "https://outlook.office.com/EWS.AccessAsUser.All" };
  string username ="USERNAME";
  string password = "PASSWORD";
  Microsoft.Identity.Client.IPublicClientApplication app;
  app = Microsoft.Identity.Client.PublicClientApplicationBuilder.Create(clientId)
                                                .WithAuthority(authority)
                                                .Build();
  var securePassword = new SecureString();
  Dictionary&lt;string, string&gt; mfa = new Dictionary&lt;string, string&gt;();
  mfa.Add("amr_values", "mfa");
  foreach (char c in password)        // you should fetch the password keystroke
              securePassword.AppendChar(c);  // by keystroke
  
  var result = app.AcquireTokenByUsernamePassword(scopes,
                  username, securePassword)
                  .WithExtraQueryParameters(mfa)
                  .ExecuteAsync().Result;
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>MsalUiRequiredException: AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access '00000002-0000-0ff1-ce00-000000000000'.</p>
  </blockquote>
  
  <p>And here is the log on Azure AD:</p>
  
  <blockquote>
    <p>User did not pass the MFA challenge (non interactive).</p>
  </blockquote>