Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to identify the type of token used for API authentication.
HLD
if token_type == '[1]': print("Use OAuth for user authorization")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing API keys with OAuth tokens.
✗ Incorrect
OAuth is a common token type used for user authorization in APIs.
2fill in blank
mediumComplete the code to decode a JWT token payload.
HLD
payload = decode_jwt(token).[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'header' or 'signature' instead of 'payload'.
✗ Incorrect
The payload part of a JWT contains the claims and user data.
3fill in blank
hardFix the error in the API key validation logic.
HLD
if api_key == [1]: grant_access()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the API key string.
✗ Incorrect
API keys are strings and must be compared as strings with quotes.
4fill in blank
hardFill both blanks to complete the OAuth token request flow.
HLD
response = request_token(client_id=[1], grant_type=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'refresh_token' grant type for initial token request.
✗ Incorrect
The client ID is a string identifier, and the grant type for initial OAuth token is 'authorization_code'.
5fill in blank
hardFill all three blanks to complete the JWT verification step.
HLD
if verify_signature(token=[1], secret=[2]) and check_expiry(token=[3]): allow_access()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently for the token.
✗ Incorrect
The token parameter should be the JWT token variable, and the secret is the key used to verify the signature.