0
0
HLDsystem_design~10 mins

API authentication (OAuth, JWT, API keys) in HLD - Interactive Code Practice

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

Complete 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'
AJWT
BOAuth
CAPIKey
DSession
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing API keys with OAuth tokens.
2fill in blank
medium

Complete the code to decode a JWT token payload.

HLD
payload = decode_jwt(token).[1]
Drag options to blanks, or click blank then click option'
Aclaims
Bheader
Csignature
Dpayload
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'header' or 'signature' instead of 'payload'.
3fill in blank
hard

Fix 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'
A12345-ABCDE
Bapi_key
C"12345-ABCDE"
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the API key string.
4fill in blank
hard

Fill 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'
A"my_client_id"
B"authorization_code"
C"refresh_token"
D"client_secret"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'refresh_token' grant type for initial token request.
5fill in blank
hard

Fill 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'
Ajwt_token
Bsecret_key
Ctoken
Daccess_token
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently for the token.