Bird
0
0

Examine this Python code snippet for exchanging an authorization code:

medium📝 Debug Q6 of 15
Rest API - Authentication and Authorization
Examine this Python code snippet for exchanging an authorization code:
import requests
response = requests.post('https://auth.example.com/token', data={'code': 'abc123', 'grant_type': 'authorization_code'})
print(response.status_code)
What is missing or incorrect in this request?
AThe HTTP method should be GET instead of POST
BThe 'client_id' and 'client_secret' parameters are missing in the POST data
CThe 'code' parameter should be sent as a URL query parameter, not in the body
DThe 'grant_type' value should be 'refresh_token' instead of 'authorization_code'
Step-by-Step Solution
Solution:
  1. Step 1: Identify required parameters

    In the Authorization Code Flow, exchanging the code for tokens requires 'client_id' and often 'client_secret' along with 'code' and 'grant_type'.
  2. Step 2: Check the request method and parameter placement

    POST is correct and parameters should be in the request body (data), which is done correctly here.
  3. Step 3: Verify parameter values

    'grant_type' is correctly set to 'authorization_code'.
  4. Final Answer:

    The request is missing 'client_id' and 'client_secret' parameters -> Option B
  5. Quick Check:

    Missing client credentials in token request [OK]
Quick Trick: Token requests need client credentials in POST data [OK]
Common Mistakes:
  • Using GET instead of POST for token exchange
  • Sending parameters as URL query instead of POST body
  • Incorrect 'grant_type' value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes