1. Concept library
  2. Java & Spring Boot
  3. Module 10: OAuth 2.0 and JWT

Concept

JWT validation

A JWT carries claims signed by the issuer. A resource server verifies the signature against the issuer's published keys, checks the expiry, issuer and audience, and only then trusts the claims.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain what a JWT carries and who signs it
  2. Validate signature, expiry, issuer and audience in a resource server
  3. Spot the token decoded without verification

In practice

A few lines that show JWT validation doing its job.

Java
// application.yml
// spring.security.oauth2.resourceserver.jwt.issuer-uri: https://auth.example.com/

@Bean
JwtDecoder jwtDecoder(OAuth2ResourceServerProperties props) {
    var decoder = JwtDecoders.<NimbusJwtDecoder>fromIssuerLocation(props.getJwt().getIssuerUri());
    var audience = new JwtClaimValidator<List<String>>("aud", aud -> aud != null && aud.contains("orders-api"));
    decoder.setJwtValidator(new DelegatingOAuth2TokenValidator<>(
        JwtValidators.createDefaultWithIssuer(props.getJwt().getIssuerUri()), audience));
    return decoder;
}

The common mistake

Watch for

Decoding the token and reading its claims without verifying the signature, or accepting any token the issuer signed without checking the audience. Both let a token meant for another API through.

What to know first

Your roadmap puts these before JWT validation, unless you already know them.

How it stays learned

Once a session shows you understand JWT validation, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled
Previous in the module← OAuth 2.0 flows
Next in the moduleOpenID Connect →