0
0
Rest APIprogramming~10 mins

Client credentials flow in Rest API - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the grant type for client credentials flow.

Rest API
POST /oauth2/token HTTP/1.1
Host: authorization-server.com
Content-Type: application/x-www-form-urlencoded

grant_type=[1]&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET
Drag options to blanks, or click blank then click option'
Aauthorization_code
Brefresh_token
Cclient_credentials
Dpassword
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'authorization_code' instead of 'client_credentials'.
Leaving the grant_type parameter empty.
2fill in blank
medium

Complete the header to specify the content type for the token request.

Rest API
POST /oauth2/token HTTP/1.1
Host: authorization-server.com
Content-Type: [1]

grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET
Drag options to blanks, or click blank then click option'
Aapplication/json
Bapplication/x-www-form-urlencoded
Ctext/plain
Dmultipart/form-data
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'application/json' which is not accepted by many OAuth2 servers for token requests.
Omitting the Content-Type header.
3fill in blank
hard

Fix the error in the token request body to correctly send client credentials.

Rest API
grant_type=client_credentials&client_id=[1]&client_secret=YOUR_CLIENT_SECRET
Drag options to blanks, or click blank then click option'
Ayour_client_id
Bclient_secret
Caccess_token
Dgrant_type
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'client_secret' as the client_id value.
Leaving the client_id blank or incorrect.
4fill in blank
hard

Complete the code to correctly parse the access token from the JSON response.

Rest API
response = '{"access_token": "abc123", "token_type": "Bearer"}'
data = json.loads(response)
access_token = data["[1]"]
Drag options to blanks, or click blank then click option'
A[
B]
Caccess_token
Dtoken
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets.
Using the wrong key name like 'token'.
5fill in blank
hard

Fill all three blanks to send a POST request with client credentials and print the access token.

Rest API
import requests
url = 'https://authorization-server.com/oauth2/token'
data = {'grant_type': '[1]', 'client_id': '[2]', 'client_secret': '[3]'}
response = requests.post(url, data=data)
print(response.json()['access_token'])
Drag options to blanks, or click blank then click option'
Aauthorization_code
Bclient_credentials
Cyour_client_id
Dyour_client_secret
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong grant type.
Swapping client ID and secret values.