0
0
Spring Bootframework~10 mins

JWT generation in Spring Boot - Interactive Code Practice

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

Complete the code to create a JWT token with a subject.

Spring Boot
String token = Jwts.builder().setSubject([1]).compact();
Drag options to blanks, or click blank then click option'
A"user123"
Bsubject
C123user
Duser123
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the subject string.
Passing a variable without quotes that is not defined.
2fill in blank
medium

Complete the code to sign the JWT token with a secret key.

Spring Boot
String token = Jwts.builder().signWith([1]).compact();
Drag options to blanks, or click blank then click option'
AKeys.secretKeyFor(SignatureAlgorithm.HS256)
BSignatureAlgorithm.HS256
C"secret"
Dnew SecretKey()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the algorithm enum directly instead of a Key.
Using a plain string instead of a Key object.
3fill in blank
hard

Fix the error in setting the expiration date for the JWT token.

Spring Boot
Date expiryDate = new Date(System.currentTimeMillis() [1] 3600000);
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction which sets expiration in the past.
Using multiplication or division which is incorrect here.
4fill in blank
hard

Fill both blanks to add claims and set expiration in the JWT builder.

Spring Boot
String token = Jwts.builder().claim("role", [1]).setExpiration([2]).compact();
Drag options to blanks, or click blank then click option'
A"admin"
Bnew Date()
CexpiryDate
D"user"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a Date for expiration.
Passing an undefined variable for claim value.
5fill in blank
hard

Fill all three blanks to build a JWT token with subject, claim, and expiration.

Spring Boot
String token = Jwts.builder().setSubject([1]).claim("scope", [2]).setExpiration([3]).compact();
Drag options to blanks, or click blank then click option'
A"user42"
B"read:write"
CexpiryDate
D"admin"
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings for expiration instead of Date.
Mixing up claim values.