Bird
0
0

What is wrong with this code snippet for exchanging an authorization code?

medium📝 Debug Q7 of 15
Rest API - Authentication and Authorization
What is wrong with this code snippet for exchanging an authorization code?
import requests
response = requests.post('https://auth.example.com/token', data={'code': 'abc123', 'grant_type': 'authorization_code'})
access_token = response.json()['access_token']
print(access_token)
AMissing client authentication in request
BNo error, code works correctly
CIncorrect HTTP method used
DResponse JSON parsing is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check required parameters for token exchange

    Authorization Code Flow requires client authentication (client_id and client_secret) during token exchange.
  2. Step 2: Identify missing client credentials

    The snippet lacks client authentication, which will cause the server to reject the request.
  3. Final Answer:

    Missing client authentication in request -> Option A
  4. Quick Check:

    Client credentials required for token exchange [OK]
Quick Trick: Always include client credentials in token request [OK]
Common Mistakes:
  • Assuming code alone is enough for token exchange
  • Thinking HTTP method should be GET
  • Believing JSON parsing fails without error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes