I have configured the resource server which verify JWT token against auth server. In code bellow you can see my configuration which has defined issuer-uri (is URI from Auth0). If user is authenticated on my public client against Auth0, this client receive JWT token from Auth0. When I call resource server with token header, user is authorized, and resources are available, but SecurityContextHolder contains only base data parsed from JWT, and not whole information about user. I have available userinfo endpoint from Auth0 which provides user's name, picture, email, etc.
My question is if I can set this user info endpoint in my resource server, to fetch this information automatically or what is the best way to do that? I would like to have this informations in SecurityContextHolder or at least user's email and user's name.
@Bean
fun filterChain(http: HttpSecurity): SecurityFilterChain {
http.authorizeRequests().anyRequest().permitAll()
.and()
.oauth2ResourceServer().jwt();
return http.build()
}
and JWT decoder bean
@Bean
fun jwtDecoder(): JwtDecoder? {
val jwtDecoder = JwtDecoders.fromOidcIssuerLocation<JwtDecoder>(issuer) as NimbusJwtDecoder
val audienceValidator: OAuth2TokenValidator<Jwt> = AudienceValidator(audience)
val withIssuer = JwtValidators.createDefaultWithIssuer(issuer)
val withAudience: OAuth2TokenValidator<Jwt> = DelegatingOAuth2TokenValidator(withIssuer, audienceValidator)
jwtDecoder.setJwtValidator(withAudience)
return jwtDecoder
}
File application.properties
spring.security.oauth2.resourceserver.jwt.issuer-uri=my-domain.com
spring.security.oauth2.resourceserver.jwt.audience=my-audience
EDIT This is payload of JWT received from Auth0
{
"iss": "https://dev-abcdefgh.us.auth0.com/",
"sub": "google-oauth2|353335637216442227159",
"aud": [
"my-audience",
"https://dev-3ag8q43b.us.auth0.com/userinfo"
],
"iat": 1663100248,
"exp": 1663186648,
"azp": "m01yBdKdQd5erBxriQde24ogfsdAsYvD",
"scope": "openid profile email"
}



