Skip to content

Commit cfc8dbe

Browse files
committed
feat/OPS-324 : 테스트 완료, 테스트 코드 제거.
1 parent e68191c commit cfc8dbe

File tree

1 file changed

+4
-80
lines changed

1 file changed

+4
-80
lines changed

src/main/java/org/tuna/zoopzoop/backend/domain/auth/controller/ApiV1AuthController.java

Lines changed: 4 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,19 @@
44
import io.swagger.v3.oas.annotations.tags.Tag;
55
import jakarta.servlet.http.HttpServletResponse;
66
import lombok.RequiredArgsConstructor;
7-
import org.springframework.beans.factory.annotation.Value;
8-
import org.springframework.http.*;
7+
import org.springframework.http.HttpHeaders;
8+
import org.springframework.http.HttpStatus;
9+
import org.springframework.http.ResponseCookie;
10+
import org.springframework.http.ResponseEntity;
911
import org.springframework.web.bind.annotation.*;
10-
import org.springframework.web.reactive.function.BodyInserters;
1112
import org.springframework.web.reactive.function.client.WebClient;
12-
import org.tuna.zoopzoop.backend.domain.auth.deprecated.KakaoTokenResponse;
13-
import org.tuna.zoopzoop.backend.domain.auth.deprecated.KakaoUserInfoResponse;
1413
import org.tuna.zoopzoop.backend.domain.auth.service.KakaoUserInfoService;
1514
import org.tuna.zoopzoop.backend.domain.member.entity.Member;
1615
import org.tuna.zoopzoop.backend.domain.member.service.MemberService;
1716
import org.tuna.zoopzoop.backend.global.config.jwt.JwtProperties;
1817
import org.tuna.zoopzoop.backend.global.rsData.RsData;
1918
import org.tuna.zoopzoop.backend.global.security.jwt.JwtUtil;
2019

21-
import java.util.HashMap;
22-
import java.util.Map;
23-
2420
@RestController
2521
@RequiredArgsConstructor
2622
@RequestMapping("api/v1/auth")
@@ -109,76 +105,4 @@ public ResponseEntity<RsData<Void>> refreshToken(@CookieValue(name = "refreshTok
109105
null
110106
));
111107
}
112-
113-
@GetMapping("/test")
114-
@Operation(summary = "소셜 로그인 테스트용 엔드 포인트")
115-
public ResponseEntity<RsData<Map<String, String>>> test(
116-
@RequestParam String code
117-
) {
118-
Map<String, Object> attributes = getAttributesFromCode(code);
119-
Member member = kakaoUserInfoService.processUser(attributes);
120-
121-
String accessToken = jwtUtil.generateToken(member);
122-
String refreshToken = jwtUtil.generateRefreshToken(member);
123-
124-
Map<String, String> tokens = new HashMap<>();
125-
tokens.put("accessToken", accessToken);
126-
tokens.put("refreshToken", refreshToken);
127-
128-
return ResponseEntity
129-
.status(HttpStatus.OK)
130-
.body(new RsData<>(
131-
"200",
132-
"로그인 테스트 완료.",
133-
tokens
134-
));
135-
}
136-
137-
@Value("${spring.security.oauth2.client.provider.kakao.token-uri}")
138-
String TOKEN_URL;
139-
140-
@Value("${spring.security.oauth2.client.provider.kakao.user-info-uri}")
141-
String USER_INFO_URL;
142-
143-
@Value("${spring.security.oauth2.client.registration.kakao.client-id}")
144-
String CLIENT_ID;
145-
146-
String REDIRECT_URI = "http://localhost:8080/oauth/kakao";
147-
148-
public Map<String, Object> getAttributesFromCode(String code) {
149-
KakaoTokenResponse tokenResponse = webClient.post()
150-
.uri(TOKEN_URL)
151-
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
152-
.body(BodyInserters.fromFormData("grant_type","authorization_code")
153-
.with("client_id", CLIENT_ID)
154-
.with("redirect_uri", REDIRECT_URI)
155-
.with("code", code))
156-
.retrieve()
157-
.bodyToMono(KakaoTokenResponse.class)
158-
.block();
159-
160-
String accessToken = tokenResponse.access_token();
161-
162-
KakaoUserInfoResponse userInfo = webClient.get()
163-
.uri(USER_INFO_URL)
164-
.headers(headers -> headers.setBearerAuth(accessToken))
165-
.retrieve()
166-
.bodyToMono(KakaoUserInfoResponse.class)
167-
.block();
168-
169-
Map<String, Object> kakaoAccountMap = new HashMap<>();
170-
171-
Map<String, Object> profileMap = new HashMap<>();
172-
profileMap.put("nickname", userInfo.kakao_account().profile().nickname());
173-
profileMap.put("profile_image_url", userInfo.kakao_account().profile().profile_image_url());
174-
175-
kakaoAccountMap.put("profile", profileMap);
176-
177-
// 4. attributes Map 생성
178-
Map<String, Object> attributes = new HashMap<>();
179-
attributes.put("id", userInfo.id());
180-
attributes.put("kakao_account", kakaoAccountMap);
181-
182-
return attributes;
183-
}
184108
}

0 commit comments

Comments
 (0)