0
0
Microservicessystem_design~10 mins

OAuth 2.0 for microservices - 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 OAuth 2.0 grant type used for microservices authentication.

Microservices
oauth2_config = {"grant_type": "[1]"}
Drag options to blanks, or click blank then click option'
Aauthorization_code
Bimplicit
Cpassword
Dclient_credentials
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a grant type that requires user interaction like authorization_code.
2fill in blank
medium

Complete the code to extract the access token from the OAuth 2.0 token response.

Microservices
access_token = token_response.get("[1]")
Drag options to blanks, or click blank then click option'
Aaccess_token
Brefresh_token
Cid_token
Dtoken_type
Attempts:
3 left
💡 Hint
Common Mistakes
Using refresh_token or id_token instead of access_token.
3fill in blank
hard

Fix the error in the code to validate the OAuth 2.0 token's expiration time.

Microservices
if current_time < token["[1]"]:
    print("Token is valid")
else:
    print("Token expired")
Drag options to blanks, or click blank then click option'
Aexp
Bexpires_in
Cexpiration
Dissued_at
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'expires_in' which is a duration, not a timestamp.
4fill in blank
hard

Fill both blanks to configure the microservice to use OAuth 2.0 token introspection endpoint.

Microservices
introspection_response = requests.post("[1]", data={"token": access_token}, auth=([2]))
Drag options to blanks, or click blank then click option'
A"https://auth.example.com/oauth2/introspect"
B"https://auth.example.com/oauth2/token"
C(client_id, client_secret)
D(access_token, refresh_token)
Attempts:
3 left
💡 Hint
Common Mistakes
Using the token endpoint URL or wrong authentication tuple.
5fill in blank
hard

Fill all three blanks to implement OAuth 2.0 token forwarding in a microservice request.

Microservices
headers = {"Authorization": "[1] [2]"}
response = requests.get(api_url, headers=headers)
print(response.status_code)
Drag options to blanks, or click blank then click option'
ABearer
Baccess_token
Ctoken
DAuthorization
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong header key or missing 'Bearer' prefix.