Bird
0
0

Given this simplified token exchange request in Python:

medium📝 Predict Output Q13 of 15
Rest API - Authentication and Authorization
Given this simplified token exchange request in Python:
import requests
response = requests.post('https://auth.example.com/token', data={
    'code': 'abc123',
    'client_id': 'myapp',
    'client_secret': 'secret',
    'redirect_uri': 'https://myapp.com/callback',
    'grant_type': 'authorization_code'
})
print(response.json().get('access_token'))
What will this code print if the exchange is successful?
AThe authorization code 'abc123'
BThe access token string from the server
CAn error message about invalid client
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Understand the request purpose

    The code sends a POST request to exchange the authorization code for an access token.
  2. Step 2: Analyze the printed output

    If successful, the server returns JSON with an 'access_token' key, which is printed.
  3. Final Answer:

    The access token string from the server -> Option B
  4. Quick Check:

    response.json()['access_token'] = access token [OK]
Quick Trick: Successful exchange returns access token, not code [OK]
Common Mistakes:
  • Printing the code instead of token
  • Expecting error message on success
  • Not accessing JSON correctly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes