Skip to content

Commit

Permalink
Merge pull request #155 from dnd-side-project/feature/#154-reissue
Browse files Browse the repository at this point in the history
[FEAT] 토큰(Access Token) 재발급 응답 수정
  • Loading branch information
f1v3-dev authored Nov 26, 2024
2 parents 32af1c4 + 38b9430 commit 7ff4353
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ public JwtProvider(JjakkakProperties jjakkakProperties, TokenProperties tokenPro
*/
public String createAccessToken(String kakaoId) {

// Date expiredDate = Date.from(Instant.now().plus(accessTokenExpirationDay, ChronoUnit.DAYS));

// fixme: 테스트를 위해 AT 만료시간 3분으로 설정함!
Date expiredDate = Date.from(Instant.now().plus(3, ChronoUnit.MINUTES));
Date expiredDate = Date.from(Instant.now().plus(accessTokenExpirationDay, ChronoUnit.DAYS));

return Jwts.builder()
.signWith(key, SignatureAlgorithm.HS256)
Expand All @@ -70,10 +67,7 @@ public String createAccessToken(String kakaoId) {
* @return JWT
*/
public String createRefreshToken(String kakaoId) {
// Date expiredDate = Date.from(Instant.now().plus(refreshTokenExpirationDay, ChronoUnit.DAYS));

// fixme: 테스트를 위해 RT 만료시간 5분으로 설정
Date expiredDate = Date.from(Instant.now().plus(5, ChronoUnit.MINUTES));
Date expiredDate = Date.from(Instant.now().plus(refreshTokenExpirationDay, ChronoUnit.DAYS));

return Jwts.builder()
.signWith(key, SignatureAlgorithm.HS256)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dnd.jjakkak.domain.member.controller;

import com.dnd.jjakkak.domain.member.dto.response.AccessTokenResponseDto;
import com.dnd.jjakkak.domain.member.dto.response.ReissueResponseDto;
import com.dnd.jjakkak.domain.member.exception.UnauthorizedException;
import com.dnd.jjakkak.domain.member.service.AuthService;
Expand Down Expand Up @@ -57,22 +58,24 @@ public ResponseEntity<Map<String, Boolean>> checkAuth(@RequestHeader(value = "Au
*/

@GetMapping("/reissue")
public ResponseEntity<Void> reissueToken(@CookieValue(value = "refresh_token", required = false) String refreshToken) {
public ResponseEntity<AccessTokenResponseDto> reissueToken(@CookieValue(value = "refresh_token", required = false) String refreshToken) {

if (Strings.isEmpty(refreshToken)) {
throw new UnauthorizedException();
}

ReissueResponseDto reissuedToken = authService.reissueToken(refreshToken);


ResponseCookie refreshCookie = CookieUtils.createCookie(
"refresh_token",
reissuedToken.getRefreshToken(),
60 * 60 * 24 * 7);

AccessTokenResponseDto responseDto = new AccessTokenResponseDto(reissuedToken.getAccessToken());

return ResponseEntity.ok()
.header(HttpHeaders.AUTHORIZATION, reissuedToken.getAccessToken())
.header(HttpHeaders.SET_COOKIE, refreshCookie.toString())
.build();
.body(responseDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.dnd.jjakkak.domain.member.dto.response;

import lombok.Getter;

/**
* {class name}.
*
* @author 정승조
* @version 2024. 11. 26.
*/
@Getter
public class AccessTokenResponseDto {

private final String accessToken;

public AccessTokenResponseDto(String accessToken) {
this.accessToken = accessToken;
}
}

0 comments on commit 7ff4353

Please sign in to comment.