title: Azure AD B2C returns AADSTS70000 error on token request
body: <p>I have a web API attempting to get set of access and refresh tokens for a B2C user. User sign-in is done through a configured "Social identity provider".</p>
  
  <p>The API receives authorization code. When exchanging code for the tokens, Azure AD B2C tenant's endpoint endpoint returns <code>invalid_grant</code> error.</p>
  
  <p>I have looked at the other answers I've found on the site. The issue still remains. Pointers are much appreciated.</p>
  
  <p>Details as follows.</p>
  
  <p>Sign-up and sign-in profiles issue claims for</p>
  
  <ul>
  <li>Given name</li>
  <li>Emails</li>
  <li>Identity provider</li>
  <li>Object ID</li>
  </ul>
  
  <p>Error from token endpoint:</p>
  
  <pre><code>{
      "error": "invalid_grant",
      "error_description": "AADSTS70000: Transmission data parser failure: Authorization Code is malformed or invalid. [...]",
      "error_codes": [
          70000
      ],
      [...]
  }
  </code></pre>
  
  <p>Authorization request looks as follows:</p>
  
  <pre><code>AUTHORIZATION_ENDPOINT = 'https://login.microsoftonline.com/&lt;tenant_id&gt;/oauth2/v2.0/authorize'
  
  authorization_url = f'{AUTHORIZATION_ENDPOINT}' \
      f'?client_id={CLIENT_ID}' \
      f'&amp;response_type=code' \
      f'&amp;redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcode' \
      f'&amp;scope=openid offline_access' \
      f'&amp;nonce=hellobob' \
      f'&amp;p=B2C_1_&lt;profile&gt;'
  </code></pre>
  
  <p>Upon user authorization, authorization code is <code>POST</code>ed by API to token endpoint. Payload is represented as a Python dictionary.</p>
  
  <pre><code>TOKEN_ENDPOINT = 'https://login.microsoftonline.com/&lt;tenant_id&gt;/oauth2/v2.0/token'
  payload = {
      'p': 'B2C_1_&lt;profile&gt;',
      'client_id': CLIENT_ID,
      'client_secret': CLIENT_SECRET,
      'code': code,
      'grant_type': 'authorization_code',
      'redirect_uri': 'http://localhost:8000/code',
      'scope': 'openid offline_access'
  }
  
  response = requests.post(TOKEN_ENDPOINT, data=payload)
  </code></pre>