Skip to content

Adding in OAuth Dependicies and redoing the principal - #54

Merged
leslyVillanueva1020 merged 4 commits into
mainfrom
Carlos/OAuth_Setup
Oct 20, 2026
Merged

leslyVillanueva1020 merged 4 commits into
mainfrom
Carlos/OAuth_Setup

Conversation

@Solian21

Copy link
Copy Markdown
Owner

Closes #50

What changed

  • Added OAuth2 Resource Server support to the API
  • Configured Google as the JWT issuer
  • Added JWT email mapping so Principal.getName() returns the authenticated user’s email.

How I tested it

  • Unit tests pass locally
  • If the API contract changed, docs/openapi.yaml is 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).

Comment on lines +82 to +86
@Bean
public JwtAuthenticationConverter jwtAuthenticationConverter() {
JwtAuthenticationConverter converter = new JwtAuthenticationConverter();
converter.setPrincipalClaimName("email");
return converter;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +69 to +72
.oauth2ResourceServer(oauth2 ->
oauth2.jwt(jwt ->
jwt.jwtAuthenticationConverter(jwtAuthenticationConverter()))
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Solian21
Solian21 requested a review from Yooze0x4c8 October 19, 2026 02:45
Yooze0x4c8
Yooze0x4c8 previously approved these changes Oct 19, 2026

@Yooze0x4c8 Yooze0x4c8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@annabelleb20 annabelleb20 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good! Thanks for adding OAuth resource server support!

@Solian21
Solian21 requested a review from Yooze0x4c8 October 20, 2026 04:01

@Yooze0x4c8 Yooze0x4c8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

@leslyVillanueva1020
leslyVillanueva1020 merged commit dca3f6c into main Oct 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

As a API developer, I want to configure Spring Boot as an OAuth2 Resource Server so that API can securely validate Google tokens

4 participants