-
Notifications
You must be signed in to change notification settings - Fork 4
Authentication
Tahmid Ahmed edited this page Nov 7, 2025
·
2 revisions
-
GET:
/api/auth/validate- Verifies whether the user is authenticated based on cookies stored in the browser. -
GET:
/api/auth/logout- Logs out the user by invalidating the session and removing cookies from the browser. It automatically returns back to the frontend with either:-
/login?success=false&message=This is the failure message. /login?success=true&message=This is the success message!- These should be handled on the frontend route.
-
-
OAuth Initiation:
GET: /api/auth/flow/{provider}- Begins the OAuth authentication process for a specific provider. (Example:/api/auth/flow/discordstarts the Discord OAuth flow.) -
OAuth Callback:
GET: /api/auth/flow/callback/{provider}- Handles the callback process after the OAuth provider returns data to authenticate the user. (Example:/api/auth/flow/callback/discordprocesses the callback from Discord OAuth.)- If successful, the user is automatically redirected to
/dashboard. - If failed, the user is automatically redirected to
/login?success=false&message=This is the failure message.- This should be handled on the frontend route.
- If successful, the user is automatically redirected to
- CSRF Protection - Automatically managed by Spring Security, so no additional configuration is required.
-
Auth Validator / Session Token Cookie Setter - Managed by the
CustomAuthenticationSuccessHandler.- Cookie Settings:
- Name:
session_token - Max Age: 30 days (configurable via a private variable).
- Name:
- Cookie Settings:
-
Protector.javais used to validate whether the user is logged in or not. It automatically handles unauthorized requests (and any otherResponseStatusException) via ControllerExceptionHandler.java -
Protected.javacan be applied to a controller method as an annotation. You can find an example inside of the file's Javadoc.-
AuthController.javacontains examples of using Protector.java to protect endpoints.
-
-
GlobalExceptionHandler.javamanages exception handling for unauthorized requests -
SecurityConfig.javaholds the OAuth provider-
CustomAuthenticationSuccessHandler.javaactually handles the process of authenticating the user once they have been successfully redirected from the OAuth provider back to our server
-
You may use the Protected annotation to validate requests manually like so:
@RestController
@RequestMapping("/api")
public class ApiController {
@PostMapping("/any-user")
public ResponseEntity<ApiResponder<Empty>> apiAnyUser(@Protected final AuthenticationObject authenticationObject) {
User user = authenticationObject.getUser(); // guaranteed for user to exist at this line.
}
@PostMapping("/admin-only")
public ResponseEntity<ApiResponder<Empty>> apiForAdmins(@Protected(admin = true) final AuthenticationObject authenticationObject) {
User user = authenticationObject.getUser(); // guaranteed for an admin user to exist at this line.
}
}You may use the Protector class to validate requests manually like so:
@RestController
@RequestMapping("/api")
public class ApiController {
private final Protector protector;
public AdminController(final Protector protector) {
this.protector = protector;
}
@PostMapping("/any-user")
public ResponseEntity<ApiResponder<Empty>> apiAnyUser(final HttpServletRequest request) {
AuthenticationObject authenticationObject = protector.validateSession(request);
User user = authenticationObject.getUser(); // guaranteed for user to exist at this line.
}
@PostMapping("/admin-only")
public ResponseEntity<ApiResponder<Empty>> apiForAdmins(final HttpServletRequest request) {
AuthenticationObject authenticationObject = protector.validateAdminSession(request);
User user = authenticationObject.getUser(); // guaranteed for an admin user to exist at this line.
}
}- Home
- Setup
- Developer Commands
- Secrets
- Technical Docs
- Feature Docs
- CI Commands
- Contributing
- Codebloom ↗
- Codebloom - Swagger Documentation ↗
- Codebloom - Staging ↗
- Codebloom - Staging - Swagger Documentation ↗
- Codebloom - Local - Swagger Documentation ↗
- Codebloom - Local - Prometheus Metrics ↗
- Grafana Dashboard - Separate domain
- Public Taskboard (Read-only) ↗