|
| 1 | +package akuma.whiplash.domains.auth.presentation; |
| 2 | + |
| 3 | +import akuma.whiplash.domains.member.domain.contants.Role; |
| 4 | +import akuma.whiplash.domains.member.persistence.entity.MemberEntity; |
| 5 | +import akuma.whiplash.domains.member.persistence.repository.MemberRepository; |
| 6 | +import akuma.whiplash.global.config.security.jwt.JwtProvider; |
| 7 | +import akuma.whiplash.global.response.ApplicationResponse; |
| 8 | +import lombok.RequiredArgsConstructor; |
| 9 | +import org.springframework.context.annotation.Profile; |
| 10 | +import org.springframework.web.bind.annotation.PostMapping; |
| 11 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 12 | +import org.springframework.web.bind.annotation.RequestParam; |
| 13 | +import org.springframework.web.bind.annotation.RestController; |
| 14 | + |
| 15 | +/** |
| 16 | + * QA 전용 토큰 발급 컨트롤러 |
| 17 | + * |
| 18 | + * - @Profile("qa") 로 QA 서버에서만 활성화, prod 배포 시 Bean 자체가 생성되지 않음 |
| 19 | + * - 소셜 로그인 없이 socialId 기반으로 JWT를 발급 |
| 20 | + * - k6 setup() 단계에서 호출해 테스트용 토큰을 자동 발급받는 용도 |
| 21 | + * |
| 22 | + * 사용 예시: |
| 23 | + * POST /qa/auth/token?socialId=QA_DUMMY_001&deviceId=k6-device-001 |
| 24 | + */ |
| 25 | +@Profile("qa") |
| 26 | +@RestController |
| 27 | +@RequiredArgsConstructor |
| 28 | +@RequestMapping("/qa/auth") |
| 29 | +public class QaAuthController { |
| 30 | + |
| 31 | + private final MemberRepository memberRepository; |
| 32 | + private final JwtProvider jwtProvider; |
| 33 | + |
| 34 | + private static final String BEARER_PREFIX = "Bearer "; |
| 35 | + |
| 36 | + @PostMapping("/token") |
| 37 | + public ApplicationResponse<String> issueToken( |
| 38 | + @RequestParam String socialId, |
| 39 | + @RequestParam(defaultValue = "k6-device") String deviceId |
| 40 | + ) { |
| 41 | + MemberEntity member = memberRepository.findBySocialId(socialId) |
| 42 | + .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 socialId: " + socialId)); |
| 43 | + |
| 44 | + String accessToken = jwtProvider.generateAccessToken( |
| 45 | + member.getId(), |
| 46 | + Role.USER, |
| 47 | + deviceId |
| 48 | + ); |
| 49 | + |
| 50 | + return ApplicationResponse.onSuccess(BEARER_PREFIX + accessToken); |
| 51 | + } |
| 52 | +} |
0 commit comments