title: How to write a python script to authenticate to Azure DevOps REST API and get the access token?
body: <p>How can I authenticate to Azure DevOps REST API in a python script? 
  I found that there are 2 methods :</p>
  
  <ul>
  <li>Using personal access token (PAT)</li>
  <li>Using OAuth 2.0</li>
  </ul>
  
  <p>I am using the second method. Followed the steps in this documentation:
  <a href="https://docs.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/oauth?view=azure-devops" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/oauth?view=azure-devops</a></p>
  
  <p>I wrote this function to autherize to azure DevOps using OAuth 2.0:</p>
  
  <pre><code>def get_authenticated():
  
      client_id = &lt; my client ID as a string &gt;
      state = "user1"
      scope = "vso.graph_manage%20vso.identity_manage%20vso.profile_write%20vso.project_manage%20vso.tokenadministration%20vso.tokens"
      callback_URL = &lt; Callback URL to my azure devops account &gt;
  
      # Azure DevOps Services authorization endpoint
      Auth_URL = "https://app.vssps.visualstudio.com/oauth2/authorize?client_id=" + client_id + "&amp;response_type=Assertion&amp;state=" + state + "&amp;scope=" + scope + "&amp;redirect_uri=" + callback_URL
      headers = {'Accept': 'application/json;api-version=1.0'}
  
      print(Auth_URL)
  
      response = requests.get(Auth_URL,headers = headers)
      print(response)
      print(response.status_code)
      print(response.headers['content-type'])
  
      response.raise_for_status() 
  </code></pre>
  
  <p>But when calling this function, output I am getting is:</p>
  
  <pre><code>&lt;Response [203]&gt;
  203
  text/html; charset=utf-8
  </code></pre>
  
  <p>The auth URL is correct because when I tried to access the same URL in a browser it successfully redirects to a form to enter azure user credentials.</p>
  
  <p>The expected behavior of the script is, when the auth_url is requested, Azure DevOps Services should ask the user to authorize. I think that should be done by prompting for username&amp;password in terminal/via a browser.</p>
  
  <p>I am totally new to python scripting and REST APIs.
  Can someone help me by pointing out the faults in my code or pointing to some samples?</p>