Skip to content

Add user registration and GitHub OAuth2 authentication features#8

Merged
PasinduOG merged 21 commits intodevfrom
feature/auth
Apr 14, 2026
Merged

Add user registration and GitHub OAuth2 authentication features#8
PasinduOG merged 21 commits intodevfrom
feature/auth

Conversation

@PasinduOG
Copy link
Copy Markdown
Owner

This pull request introduces comprehensive user authentication and security enhancements, including integration with Spring Security and OAuth2 (GitHub), as well as improvements to user registration and profile management. It also updates the user data model and sample data to support secure password storage and user roles.

Authentication and Security Integration:

  • Added spring-boot-starter-security and spring-boot-starter-oauth2-client dependencies to enable security and OAuth2 support. (pom.xml)
  • Introduced SecurityConfig to configure HTTP security, form login, OAuth2 login with GitHub, and logout handling. (SecurityConfig.java)
  • Added GitHub OAuth2 client configuration to application.yml.
  • Added a PasswordEncoder bean using BCrypt for secure password hashing. (AppConfig.java) [1] [2]

User Registration and Profile Management:

  • Refactored user registration to use a new RegisterRequest DTO, added password hashing, and checked for duplicate emails. (RegisterRequest.java, UserService/Impl, UserController.java) [1] [2] [3] [4] [5]
  • Added endpoints and service methods for updating user profiles and fetching users by ID. (UserController.java, UserService/Impl, UserRepository/Impl) [1] [2] [3] [4] [5]

OAuth2 User Handling:

  • Implemented CustomOAuth2UserService to register new users authenticated via GitHub, assign roles based on email, and log registration events. (CustomOAuth2UserService.java)

Sample Data and Password Security:

  • Updated sample user data to use valid emails and BCrypt-hashed passwords for consistency with new security requirements. (V3__insert_sample_data.sql)

@PasinduOG PasinduOG self-assigned this Apr 11, 2026
@PasinduOG PasinduOG added the enhancement New feature or request label Apr 11, 2026
@PasinduOG PasinduOG requested a review from Copilot April 11, 2026 18:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces Spring Security-based authentication (form login + GitHub OAuth2), refactors user registration to hash passwords via BCrypt, and adds basic user profile update capabilities backed by the existing JDBC repository layer.

Changes:

  • Added Spring Security + OAuth2 client dependencies and introduced SecurityConfig + CustomOAuth2UserService for GitHub login.
  • Refactored user registration to use RegisterRequest, hash passwords, and add duplicate-email handling.
  • Added user profile update and user-by-id retrieval in service/repository/controller layers; updated sample users to use BCrypt hashes.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
pom.xml Adds Spring Security and OAuth2 client dependencies.
src/main/resources/application.yml Adds GitHub OAuth client config via environment variables.
src/main/resources/db/migration/V3__insert_sample_data.sql Replaces dummy hashes with BCrypt hashes and updates sample emails.
src/main/java/dev/pasinduog/eventsphere/config/SecurityConfig.java Defines security filter chain (auth rules, login, OAuth2, logout).
src/main/java/dev/pasinduog/eventsphere/config/AppConfig.java Adds PasswordEncoder bean (BCrypt).
src/main/java/dev/pasinduog/eventsphere/service/CustomOAuth2UserService.java Registers GitHub-authenticated users into the local users table.
src/main/java/dev/pasinduog/eventsphere/dto/RegisterRequest.java Introduces DTO for registration payload.
src/main/java/dev/pasinduog/eventsphere/service/UserService.java Updates service contract for registration + adds profile-related methods.
src/main/java/dev/pasinduog/eventsphere/service/impl/UserServiceImpl.java Implements password hashing, duplicate email check, get-by-id, update.
src/main/java/dev/pasinduog/eventsphere/controller/UserController.java Updates registration endpoint payload + adds profile update endpoint.
src/main/java/dev/pasinduog/eventsphere/repository/UserRepository.java Adds update(User) method.
src/main/java/dev/pasinduog/eventsphere/repository/impl/UserRepositoryImpl.java Implements SQL update for profile fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/java/dev/pasinduog/eventsphere/controller/UserController.java Outdated
Comment thread src/main/java/dev/pasinduog/eventsphere/config/SecurityConfig.java
Comment thread src/main/java/dev/pasinduog/eventsphere/config/SecurityConfig.java Outdated
Comment thread src/main/java/dev/pasinduog/eventsphere/config/SecurityConfig.java Outdated
Comment thread src/main/java/dev/pasinduog/eventsphere/service/CustomOAuth2UserService.java Outdated
Comment thread src/main/java/dev/pasinduog/eventsphere/config/SecurityConfig.java
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds authentication capabilities to the EventSphere backend, including local user registration with hashed passwords, JWT-based API authentication, and GitHub OAuth2 login integration, along with related schema/config updates.

Changes:

  • Introduces Spring Security + GitHub OAuth2 login flow, plus JWT generation/validation and a JWT request filter.
  • Refactors user registration to use a DTO and BCrypt hashing; adds endpoints for “me” and profile updates.
  • Updates DB schema/sample data to support roles/event statuses and hashed passwords.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
src/main/resources/db/migration/V1__init_schema.sql Adds roles/event_statuses tables and foreign keys for role/status values.
src/main/resources/db/migration/V3__insert_sample_data.sql Seeds roles/statuses and updates sample users to use BCrypt password hashes.
src/main/resources/application.yml Adds GitHub OAuth2 client config and JWT/admin configuration keys.
src/main/java/dev/pasinduog/eventsphere/service/UserService.java Updates registration contract and adds profile/user lookup APIs.
src/main/java/dev/pasinduog/eventsphere/service/OAuth2CodeService.java Defines one-time code generation/validation for OAuth2-to-JWT handoff.
src/main/java/dev/pasinduog/eventsphere/service/JwtService.java Defines JWT operations for token lifecycle and claims extraction.
src/main/java/dev/pasinduog/eventsphere/service/impl/UserServiceImpl.java Implements DTO-based registration, hashing, and profile update support.
src/main/java/dev/pasinduog/eventsphere/service/impl/OAuth2CodeServiceImpl.java Implements in-memory OAuth2 code storage.
src/main/java/dev/pasinduog/eventsphere/service/impl/JwtServiceImpl.java Implements JWT creation and validation via JJWT.
src/main/java/dev/pasinduog/eventsphere/service/impl/AiMatchmakingServiceImpl.java Updates Gemini config property keys used by matchmaking.
src/main/java/dev/pasinduog/eventsphere/service/CustomOAuth2UserService.java Registers GitHub-authenticated users and fetches email when missing.
src/main/java/dev/pasinduog/eventsphere/repository/UserRepository.java Adds update operation to repository contract.
src/main/java/dev/pasinduog/eventsphere/repository/impl/UserRepositoryImpl.java Adds update logic and expands queries to include password_hash where needed.
src/main/java/dev/pasinduog/eventsphere/model/User.java Implements Spring Security UserDetails for DB-backed users.
src/main/java/dev/pasinduog/eventsphere/filter/JwtAuthFilter.java Adds JWT auth filter to populate SecurityContext from Bearer tokens.
src/main/java/dev/pasinduog/eventsphere/exception/InvalidAuthCodeException.java Adds a typed exception for invalid OAuth2 callback codes.
src/main/java/dev/pasinduog/eventsphere/dto/RegisterRequest.java Adds registration DTO.
src/main/java/dev/pasinduog/eventsphere/dto/OAuth2CallbackRequest.java Adds DTO for exchanging OAuth2 callback code for a JWT.
src/main/java/dev/pasinduog/eventsphere/dto/LoginResponse.java Adds JWT login response DTO.
src/main/java/dev/pasinduog/eventsphere/dto/LoginRequest.java Adds password login request DTO.
src/main/java/dev/pasinduog/eventsphere/controller/UserController.java Adds secured user lookup endpoints and profile update (“me”) APIs.
src/main/java/dev/pasinduog/eventsphere/controller/EventController.java Adds method-level authorization annotations to event endpoints.
src/main/java/dev/pasinduog/eventsphere/controller/AuthController.java Adds password login and OAuth2 callback-to-JWT exchange endpoints.
src/main/java/dev/pasinduog/eventsphere/config/SecurityConfig.java Configures Spring Security, JWT filter, OAuth2 login, and CORS.
src/main/java/dev/pasinduog/eventsphere/config/AppConfig.java Adds BCrypt PasswordEncoder and OpenAPI bearer auth configuration.
pom.xml Adds Spring Security, OAuth2 client, and JJWT dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/java/dev/pasinduog/eventsphere/repository/impl/UserRepositoryImpl.java Outdated
Comment thread src/main/java/dev/pasinduog/eventsphere/config/SecurityConfig.java Outdated
Comment thread src/main/java/dev/pasinduog/eventsphere/config/SecurityConfig.java Outdated
Comment thread src/main/java/dev/pasinduog/eventsphere/config/SecurityConfig.java
Comment thread src/main/java/dev/pasinduog/eventsphere/config/SecurityConfig.java
Comment thread src/main/java/dev/pasinduog/eventsphere/controller/UserController.java Outdated
Comment thread src/main/java/dev/pasinduog/eventsphere/config/AppConfig.java Outdated
Comment thread src/main/resources/db/migration/V1__init_schema.sql
Comment thread src/main/resources/db/migration/V3__insert_sample_data.sql
PasinduOG and others added 4 commits April 13, 2026 15:46
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…HttpUrl removed in Spring 7

Agent-Logs-Url: https://github.com/PasinduOG/eventsphere/sessions/e1363c15-ab4d-4386-9e06-36516a988e9b

Co-authored-by: PasinduOG <126347762+PasinduOG@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI and others added 2 commits April 13, 2026 18:35
…ror handling in fetchEmailFromGitHub

Agent-Logs-Url: https://github.com/PasinduOG/eventsphere/sessions/2c67ab62-fd77-4811-9b65-06d6ca0e8b0f

Co-authored-by: PasinduOG <126347762+PasinduOG@users.noreply.github.com>

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
String effectiveRole = (this.role != null) ? this.role : "ATTENDEE";
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@copilot IntelliJ said "this.role ! = null" is always true so I think this is not necessary

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Simplified in commit 2590284 — since the class is annotated with @NullMarked, role is treated as non-null and the ternary guard was redundant. getAuthorities() now directly returns List.of(new SimpleGrantedAuthority(this.role)).

…der @NullMarked

Agent-Logs-Url: https://github.com/PasinduOG/eventsphere/sessions/6c9317dc-6684-4dc3-ba7c-c99d6875a8b1

Co-authored-by: PasinduOG <126347762+PasinduOG@users.noreply.github.com>
@PasinduOG PasinduOG merged commit d4999d3 into dev Apr 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants