title: Getting authenticated to personal OneDrive
body: <p>am trying to get authenticated with a Python to OneDrive (personal, not for business). I've registered an app in Azure AD, got client id and secret (turned to be not needed, as I am using 'desktop' app which is public and not using a secret), and Using browser and postman, managed to obtain an access token.</p>
  <p>trying 2 different options now, both with no luck.</p>
  <pre><code>import hidden
  from hidden import oauthr
  import requests
  import json
  
  
  client_secret = oauthr()[&quot;consumer_secret&quot;]
  client_id = oauthr()[&quot;consumer_key&quot;]
  scope = 'Files.ReadWrite.All'
  redirect_uri = &quot;http://localhost/auth-response&quot;
  code = oauthr()[&quot;code&quot;]
  token = oauthr()[&quot;token_secret&quot;]
  
  
  RootFolder = 'https://api.onedrive.com/v1.0/drive/root:/'
  
  r = requests.get(RootFolder, headers = {'Authorization': 'Bearer ' + token})
  
  content=json.loads(r.content)
  print(content)
  </code></pre>
  <p>This one results in: {'error': {'code': 'unauthenticated', 'message': 'Authentication failed'}}</p>
  <p>Second thing I try is MSAL:</p>
  <pre><code>import hidden
  from hidden import oauthr
  import requests
  import json
  
  from msal import PublicClientApplication
  
  
  client_secret = oauthr()[&quot;consumer_secret&quot;]
  client_id = oauthr()[&quot;consumer_key&quot;]
  scopes = ['https://graph.microsoft.com/.default']
  redirect_uri = &quot;http://localhost/auth-response&quot;
  code = oauthr()[&quot;code&quot;]
  token = oauthr()[&quot;token_secret&quot;]
  
  user = input(&quot;user: &quot;)
  pwd = input(&quot;pwd: &quot;)
  print('scopes are: ', scopes, ' the data type is: ',type(scopes) )
  
  app = PublicClientApplication(
      client_id,
      authority=&quot;https://login.microsoftonline.com/UsadyProgimnasia.onmicrosoft.com&quot;)
      
  result = None
  
  flow = app.initiate_device_flow(scopes = scopes)
      
  accounts = app.get_accounts()
  if accounts:
      # If so, you could then somehow display these accounts and let end user choose
      print(&quot;Pick the account you want to use to proceed:&quot;)
      for a in accounts:
          print(a[&quot;username&quot;])
      # Assuming the end user chose this one
      chosen = accounts[0]
      # Now let's try to find a token in cache for this account
      result = app.acquire_token_silent([scopes], account=chosen)
  
     
  if not result:
      print('So no suitable token exists in cache. Let\'s get a new one from Azure AD')
      #result = app.acquire_token_by_username_password(user, pwd, scopes)
      result = app.acquire_token_by_authorization_code(code, scopes, redirect_uri=redirect_uri, nonce=None, claims_challenge=None)
      #result = app.acquire_token_by_device_flow(flow, claims_challenge=None)
      if &quot;access_token&quot; in result:
          print(result[&quot;access_token&quot;])  # Yay!
      else:
          print(result.get(&quot;error&quot;))
          print(result.get(&quot;error_description&quot;))
          print(result.get(&quot;correlation_id&quot;))  # You may need this when reporting a bug
  </code></pre>
  <p>This gives a invalid_grant AADSTS70000121: The passed grant is from a personal Microsoft account and is required to be sent to the /consumers or /common endpoint.</p>
  <p>Would appreciate an advice, chaps</p>
  <p>Regards</p>