-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
209 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/backend/Eyesee/src/main/java/com/fortune/eyesee/controller/AuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.fortune.eyesee.controller; | ||
|
||
import com.fortune.eyesee.common.exception.BaseException; | ||
import com.fortune.eyesee.common.response.BaseResponse; | ||
import com.fortune.eyesee.common.response.BaseResponseCode; | ||
|
||
import com.fortune.eyesee.dto.AccessTokenResponseDTO; | ||
import com.fortune.eyesee.dto.RefreshTokenRequestDTO; | ||
import com.fortune.eyesee.service.AuthService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/api/auth") | ||
public class AuthController { | ||
|
||
@Autowired | ||
private AuthService authService; | ||
|
||
@PostMapping("/refresh") | ||
public ResponseEntity<BaseResponse<AccessTokenResponseDTO>> refreshAccessToken(@RequestBody RefreshTokenRequestDTO refreshTokenRequestDTO) { | ||
try { | ||
AccessTokenResponseDTO accessTokenResponseDTO = authService.refreshToken(refreshTokenRequestDTO); | ||
|
||
return ResponseEntity.ok(new BaseResponse<>(accessTokenResponseDTO, "토큰 갱신 성공")); | ||
} catch (Exception e) { | ||
throw new BaseException(BaseResponseCode.TOKEN_ERROR); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/backend/Eyesee/src/main/java/com/fortune/eyesee/dto/AccessTokenResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.fortune.eyesee.dto; | ||
|
||
public class AccessTokenResponseDTO { | ||
private String access_token; | ||
|
||
public AccessTokenResponseDTO(String accessToken) { | ||
this.access_token = accessToken; | ||
} | ||
|
||
public String getAccess_token() { | ||
return access_token; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/backend/Eyesee/src/main/java/com/fortune/eyesee/dto/RefreshTokenRequestDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.fortune.eyesee.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class RefreshTokenRequestDTO { | ||
private String refresh_token; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/backend/Eyesee/src/main/java/com/fortune/eyesee/service/AuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.fortune.eyesee.service; | ||
|
||
import com.fortune.eyesee.common.exception.BaseException; | ||
import com.fortune.eyesee.common.response.BaseResponseCode; | ||
import com.fortune.eyesee.dto.AccessTokenResponseDTO; | ||
import com.fortune.eyesee.dto.RefreshTokenRequestDTO; | ||
import com.fortune.eyesee.utils.JwtUtil; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class AuthService { | ||
|
||
private final JwtUtil jwtUtil; | ||
|
||
public AuthService(JwtUtil jwtUtil) { | ||
this.jwtUtil = jwtUtil; | ||
} | ||
|
||
public AccessTokenResponseDTO refreshToken(RefreshTokenRequestDTO request) { | ||
// 리프레시 토큰 검증 (validateToken에서 예외 처리) | ||
jwtUtil.validateToken(request.getRefresh_token()); | ||
|
||
// 리프레시 토큰에서 사용자 ID 추출 | ||
Integer adminId = jwtUtil.getAdminIdFromToken(request.getRefresh_token()); | ||
|
||
// 새로운 액세스 토큰 발급 | ||
String newAccessToken = jwtUtil.generateToken(adminId); | ||
|
||
return new AccessTokenResponseDTO(newAccessToken); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.