🔐 Jwt vs JwtAuthenticationToken — What's the Relationship?

Think of it like this:

1. Jwt is the raw token.

It's just a data object that holds everything inside the token — like:

🧠 Analogy: This is like the contents of someone's ID card.


Jwt jwt = Jwt.withTokenValue("mock-token")
             .claim("sub", "123")
             .claim("email", "[email protected]")
             .build();


2. JwtAuthenticationToken is a Spring Security wrapper.

Spring uses it to:

🧠 Analogy: This is the user login session, built from the ID card.


JwtAuthenticationToken auth = new JwtAuthenticationToken(jwt, authorities);

Now you can access things like:


auth.getPrincipal(); // the Jwt object
auth.getName();      // the "sub" claim (like user ID)
auth.getAuthorities(); // converted roles