Skip to content

Commit

Permalink
๐Ÿš€ [Deploy] - Reissue ํ† ํฐ ๋ฐ ํฌ๋ ˆ๋ด์…œ ์—…๋ฐ์ดํŠธ (#32)
Browse files Browse the repository at this point in the history
* Feat: customException ๊ตฌํ˜„

* Feat: responseDto ๊ตฌํ˜„

* Feat: ๋‚ด ๊ทผ์ฒ˜ ํ‚ฅ๋ณด๋“œ ์ฃผ์ฐจ์žฅ ์ฐพ๊ธฐ API ๊ตฌํ˜„

* Fix: BoardingRecord ๋„๋ฉ”์ธ ์ˆ˜์ •

* Feat: Spring Security, JWT Cookie, ์†Œ์…œ ๋กœ๊ทธ์ธ ๊ธฐ๋Šฅ ๊ตฌํ˜„

* Feat: Spring Security, JWT Cookie, ์†Œ์…œ ๋กœ๊ทธ์ธ ๊ธฐ๋Šฅ ๊ตฌํ˜„

* Fix: ์ฝ”๋“œ ์—๋Ÿฌ ์ˆ˜์ •

* Refactor: ์•„์ง ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ฝ”๋“œ ์‚ญ์ œ

* Feat: oauth2 ์˜์กด์„ฑ ์ถ”๊ฐ€

* Chore: Credentials ์ถ”๊ฐ€

* โœจ [Feature] - ์„œ๋ฒ„ ๋‚ ์งœ ์„ค์ • ๋ฐ ์œ ์ € ๋‹‰๋„ค์ž„ ์„ค์ • (#15)

* Feat: ์Šคํ”„๋ง ์„œ๋ฒ„ ์‹œ๊ฐ„ ํ•œ๊ตญ์œผ๋กœ ์„ค์ •

* Feat: ์‚ฌ์šฉ์ž ๋‹‰๋„ค์ž„ ์ง€์ • ๋กœ์ง ์ถ”๊ฐ€

* Fix: ์ดˆ๊ธฐ ํฌ์ธํŠธ ์„ค์ •

* Fix: nickname ์—๋Ÿฌ ์ˆ˜์ • (#18)

* Fix: BoardingRecord ๋„๋ฉ”์ธ ์ˆ˜์ •

* Feat: ๋””ํŽœ๋˜์‹œ ์ถ”๊ฐ€

* Feat: ErrorCode ์ถ”๊ฐ€

* Feat: Image API ๊ตฌํ˜„

* Feat: WebClientConfig ๊ตฌํ˜„

* Feat: S3ClientConfig ๊ตฌํ˜„

* Feat: BoardingRecord API ๊ตฌํ˜„

* Feat: ์ฃผ์ฐจ์žฅ ์˜ˆ์ธก ๊ฒฐ๊ณผ ๊ด€๋ จ ๊ธฐ๋Šฅ ์ถ”๊ฐ€

* Feat: ํƒ‘์Šน ๊ธฐ๋ก ์ €์žฅ API ๊ตฌํ˜„

* Fix: ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ ์ˆ˜์ •

* Feat: ์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง ์ง„ํ–‰

* Chore: Credentials ์ˆ˜์ • (#29)

* !HOTFIX: ์„œ๋ธŒ ๋ชจ๋“ˆ ์ปจํ”Œ๋ฆญํŠธ ํ•ด๊ฒฐ

* โœจ [Feature] - Reissue ํ† ํฐ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ (#31)

* Chore: Credentials ์ˆ˜์ •

* Feat: Reissue ํ† ํฐ ๊ธฐ๋Šฅ ๊ตฌํ˜„

* Chore: Credentials ์ถ”๊ฐ€

---------

Co-authored-by: Jang99u <[email protected]>
Co-authored-by: ๋ฏผ์žฅ๊ทœ <[email protected]>
  • Loading branch information
3 people authored May 8, 2024
1 parent 6414759 commit d2e0c3d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/java/ice/spot/controller/AuthController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package ice.spot.controller;

import ice.spot.annotation.UserId;
import ice.spot.constant.Constants;
import ice.spot.dto.global.ResponseDto;
import ice.spot.dto.request.OauthSignUpDto;
import ice.spot.dto.response.JwtTokenDto;
import ice.spot.exception.CommonException;
import ice.spot.exception.ErrorCode;
import ice.spot.service.AuthService;
import ice.spot.util.CookieUtil;
import ice.spot.util.HeaderUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -17,11 +26,31 @@
@RequiredArgsConstructor
public class AuthController {

@Value("${server.domain}")
private String domain;

private final AuthService authService;

@PostMapping("/oauth2/sign-up")
public ResponseDto<?> signUp(@UserId Long userId, @RequestBody OauthSignUpDto oauthSignUpDto) {
authService.signUp(userId, oauthSignUpDto);
return ResponseDto.ok(null);
}

@PostMapping("/auth/reissue")
public ResponseDto<?> reissue(
HttpServletRequest request,
HttpServletResponse response,
@UserId Long userId){
log.info("controller ์ง„์ž… ์„ฑ๊ณต");
String refreshToken = HeaderUtil.refineHeader(request, Constants.PREFIX_AUTH, Constants.PREFIX_BEARER)
.orElseThrow(() -> new CommonException(ErrorCode.INVALID_HEADER_VALUE));
log.info("ํ—ค๋”๊ฐ’ ์กฐํšŒ ์„ฑ๊ณต");
JwtTokenDto jwtTokenDto = authService.reGenerateTokens(userId, refreshToken);

CookieUtil.addCookie(response, domain, Constants.ACCESS_COOKIE_NAME, jwtTokenDto.accessToken());
CookieUtil.addSecureCookie(response, domain, Constants.REFRESH_COOKIE_NAME, jwtTokenDto.refreshToken(), 60 * 60 * 24 * 14);

return ResponseDto.ok(jwtTokenDto);
}
}
14 changes: 14 additions & 0 deletions src/main/java/ice/spot/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import ice.spot.domain.User;
import ice.spot.dto.request.OauthSignUpDto;
import ice.spot.dto.response.JwtTokenDto;
import ice.spot.exception.CommonException;
import ice.spot.exception.ErrorCode;
import ice.spot.repository.UserRepository;
import ice.spot.util.JwtUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -16,6 +18,7 @@
public class AuthService {

private final UserRepository userRepository;
private final JwtUtil jwtUtil;

@Transactional
public void signUp(Long userId, OauthSignUpDto oauthSignUpDto){
Expand All @@ -25,4 +28,15 @@ public void signUp(Long userId, OauthSignUpDto oauthSignUpDto){
oauthUser.register(oauthSignUpDto.nickname());
}

@Transactional
public JwtTokenDto reGenerateTokens(Long userId, String refreshToken){
log.info("re generate tokens ์ง„์ž…์„ฑ๊ณต");
User loginUser = userRepository.findByIdAndRefreshToken(userId, refreshToken)
.orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_USER));
log.info("์œ ์ € ์กฐํšŒ ์„ฑ๊ณต");
JwtTokenDto jwtTokenDto = jwtUtil.generateTokens(loginUser.getId(), loginUser.getRole());

loginUser.updateRefreshToken(jwtTokenDto.refreshToken());
return jwtTokenDto;
}
}

0 comments on commit d2e0c3d

Please sign in to comment.