Compare commits
2 Commits
d323e4f8f7
...
4e2da0debc
| Author | SHA1 | Date | |
|---|---|---|---|
|
4e2da0debc
|
|||
|
0815d1d618
|
@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* REST controller for user authentication endpoints (login, logout).
|
* REST controller for user authentication endpoints (login, logout).
|
||||||
@@ -43,12 +44,14 @@ public class AuthController {
|
|||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public ResponseEntity<UserResponse> login(@Validated @RequestBody LoginRequest request) {
|
public ResponseEntity<UserResponse> login(@Validated @RequestBody LoginRequest request) {
|
||||||
var user = authService.login(request);
|
var user = authService.login(request);
|
||||||
|
var currentTime = LocalDateTime.now();
|
||||||
var accessToken = tokenClient.generateToken(user);
|
var accessToken = tokenClient.generateToken(user);
|
||||||
var accessTokenCookie = cookieService.buildCookie(CookieName.ACCESS_TOKEN, accessToken);
|
var accessTokenCookie = cookieService.buildCookie(CookieName.ACCESS_TOKEN, accessToken);
|
||||||
|
var cookieMaxAge = accessTokenCookie.getMaxAge();
|
||||||
|
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.header(HttpHeaders.SET_COOKIE, accessTokenCookie.toString())
|
.header(HttpHeaders.SET_COOKIE, accessTokenCookie.toString())
|
||||||
.body(UserResponse.from(user));
|
.body(UserResponse.from(user, currentTime.plus(cookieMaxAge)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresAuth
|
@RequiresAuth
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.onixbyte.deltaforceguide.domain.dto;
|
|||||||
|
|
||||||
import com.onixbyte.deltaforceguide.domain.entity.User;
|
import com.onixbyte.deltaforceguide.domain.entity.User;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response DTO for a user account, including associated credentials.
|
* Response DTO for a user account, including associated credentials.
|
||||||
*
|
*
|
||||||
@@ -10,13 +12,15 @@ import com.onixbyte.deltaforceguide.domain.entity.User;
|
|||||||
public record UserResponse(
|
public record UserResponse(
|
||||||
Long id,
|
Long id,
|
||||||
String username,
|
String username,
|
||||||
String email
|
String email,
|
||||||
|
LocalDateTime expiration
|
||||||
) {
|
) {
|
||||||
public static UserResponse from(User user) {
|
public static UserResponse from(User user, LocalDateTime expiration) {
|
||||||
return new UserResponse(
|
return new UserResponse(
|
||||||
user.getId(),
|
user.getId(),
|
||||||
user.getUsername(),
|
user.getUsername(),
|
||||||
user.getEmail()
|
user.getEmail(),
|
||||||
|
expiration
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ public class GitHubWebhookInterceptor implements HandlerInterceptor {
|
|||||||
|
|
||||||
var body = req.getBodyString();
|
var body = req.getBodyString();
|
||||||
try {
|
try {
|
||||||
var computed = "sha256=" + CryptoUtil.hmacSha256(secret, body);
|
var computed = "sha256=" + CryptoUtil.hmacSha256(body, secret);
|
||||||
|
|
||||||
if (!MessageDigest.isEqual(
|
if (!MessageDigest.isEqual(
|
||||||
computed.getBytes(StandardCharsets.UTF_8),
|
computed.getBytes(StandardCharsets.UTF_8),
|
||||||
|
|||||||
@@ -73,8 +73,7 @@ public class WebhookService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
var data = yaml.<Map<String, Object>>load(parsedYaml);
|
||||||
var data = (Map<String, Object>) yaml.load(parsedYaml);
|
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
log.warn("Empty YAML block in issue #{}", issue.number());
|
log.warn("Empty YAML block in issue #{}", issue.number());
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user