0
0
Microservicessystem_design~10 mins

JWT token propagation in 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 extract the JWT token from the HTTP Authorization header.

Microservices
auth_header = request.headers.get('Authorization')
token = auth_header.split(' ')[[1]]
Drag options to blanks, or click blank then click option'
A1
B2
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 0 returns 'Bearer' instead of the token.
Using -1 might work but is less clear.
2fill in blank
medium

Complete the code to add the JWT token to the outgoing HTTP request headers for propagation.

Microservices
headers = {}
headers['Authorization'] = 'Bearer ' + [1]
Drag options to blanks, or click blank then click option'
Aauth_token
Btoken
Caccess_token
Djwt_token
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variable names like 'auth_token' or 'jwt_token' without declaration.
3fill in blank
hard

Fix the error in the code that forwards the JWT token in a microservice call.

Microservices
response = requests.get(url, headers=[1])
Drag options to blanks, or click blank then click option'
Aauth_header
BAuthorization
Cheader
Dheaders
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of a dictionary causes runtime errors.
Using wrong variable names leads to NameError.
4fill in blank
hard

Fill both blanks to correctly extract and propagate the JWT token in a microservice environment.

Microservices
auth_header = request.headers.get('[1]')
token = auth_header.split(' ')[[2]]
Drag options to blanks, or click blank then click option'
AAuthorization
BAuthentication
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Authentication' instead of 'Authorization' header.
Using index 0 returns the word 'Bearer' instead of the token.
5fill in blank
hard

Fill all three blanks to create a dictionary that propagates the JWT token only if it exists and is valid.

Microservices
if [1] and [2].startswith('Bearer '):
    headers = {'Authorization': [3]
else:
    headers = {}
Drag options to blanks, or click blank then click option'
Aauth_header
Dauth_header.split(' ')[1]
Attempts:
3 left
💡 Hint
Common Mistakes
Not checking if the header exists before accessing it.
Using the whole header string instead of just the token.