title: Login to azure oauth2 with on premise adfs
body: <p>I am trying to connect with oauth2 to our azure tenant inside some python script. I created an app registration and permitted some API access for it.</p>
  
  <p>When I try to connect with username and password, I will just get an <code>Error Code 50126</code> (Invalid username or password).</p>
  
  <p>If I define some secret inside my app registration and switch to client secret as grant_type, I will have access to my app. </p>
  
  <p>But I want to use username and password. Username is <code>user@domain.com</code> and password is correct, too. </p>
  
  <p>So I think our ADFS server is making problems.</p>
  
  <p>We are using some on premise AD and sync the user data to azure with Azure Connect, but we do not sync the passwords. So logins to Azure are forwarded to our adfs instance and are done on premise.</p>
  
  <p>How can I implement that logic in my script? I need something like a redirect to adfs with my username and password and need the correct response to logon to azure.</p>
  
  <p>I already searched a lot for this, but did not find an answer. It is not possible to me to activate the password sync.</p>
  
  <p>My connection parameter to azure is like </p>
  
  <pre><code>tokenpost = {
      'client_id':clientid,
      'resource':crmorg,
      'password':password,
      'username':'user@domain.com',
      'grant_type':'password'
  }
  tokenres = requests.post('https://login.microsoftonline.com/&lt;tenantid&gt;/oauth2/token', data=tokenpost)
  </code></pre>
  
  <p>Some had the same problem?</p>
  
  <p>Best,
  Robin</p>