Repository navigation
Adding in OAuth Dependicies and redoing the principal - #54
Conversation
| @Bean | ||
| public JwtAuthenticationConverter jwtAuthenticationConverter() { | ||
| JwtAuthenticationConverter converter = new JwtAuthenticationConverter(); | ||
| converter.setPrincipalClaimName("email"); | ||
| return converter; |
There was a problem hiding this comment.
The converter changes the principal name to email, but it never loads the user’s database role. The default converter derives permissions from token scopes; it does not turn a database ADMIN role into ROLE_ADMIN. Consequently, even a database administrator signing in with a valid Google token receives 403 from administrator endpoints. Load the matched user’s role and add the corresponding authority during authentication, as required by issue #50
| .oauth2ResourceServer(oauth2 -> | ||
| oauth2.jwt(jwt -> | ||
| jwt.jwtAuthenticationConverter(jwtAuthenticationConverter())) | ||
| ); |
There was a problem hiding this comment.
The custom 401 handler is configured under exceptionHandling(), but the new resource server uses its own authentication failure handler. An expired or malformed Bearer token can therefore return 401 without the required Problem Details JSON body. Configure .authenticationEntryPoint(entryPoint) inside oauth2ResourceServer() and test an invalid token, checking both the body and WWW-Authenticate header.
Yooze0x4c8
left a comment
There was a problem hiding this comment.
I believe this code is good!
But could you remove the .lck and .part files under api/.gradle-user-home from this PR? They’re temporary Gradle files that appear to have been committed accidentally.
…851m17nbqdsro2tv/gradle-9.7.1-bin.zip.part
…851m17nbqdsro2tv/gradle-9.7.1-bin.zip.lck
annabelleb20
left a comment
There was a problem hiding this comment.
Looks really good! Thanks for adding OAuth resource server support!
Closes #50
What changed
Principal.getName()returns the authenticated user’s email.How I tested it
docs/openapi.yamlis updated and lints clean (npx @redocly/cli lint docs/openapi.yaml)Reviewers
2 approving teammates who are not the author (1 for a team of 3).