Skip to content

Commit

Permalink
fix: redirect_uri, 헤더 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
EUNCHAEv1006 committed Jan 23, 2024
1 parent e5095fe commit a333ea5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
import com.HHive.hhive.global.common.CommonResponse;
import com.HHive.hhive.global.jwt.JwtUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -126,18 +123,12 @@ public ResponseEntity<CommonResponse> getMyHives(

@GetMapping("/kakao/callback")
public String kakaoLogin(@RequestParam String code, HttpServletResponse response) throws JsonProcessingException {
System.out.println(code);

// jwt 토큰 반환
String token = kaKaoService.kakaoLogin(code);

// 반환된 토큰을 쿠키에 넣음
Cookie cookie = new Cookie(jwtUtil.JWT_COOKIE_NAME, token.substring(7));
cookie.setPath("/");
response.setHeader(JwtUtil.AUTHORIZATION_HEADER, JwtUtil.BEARER_PREFIX + token);

// + response 객체에 넣음
response.addCookie(cookie);

return "redirect:/";
return "redirect:https://hhive.store/";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.HHive.hhive.domain.user.dto.KakaoUserInfoDTO;
import com.HHive.hhive.domain.user.entity.User;
import com.HHive.hhive.domain.user.repository.UserRepository;
import com.HHive.hhive.global.exception.user.AlreadyExistKakaoIdException;
import com.HHive.hhive.global.jwt.JwtUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -63,7 +62,7 @@ private String getToken(String code) throws JsonProcessingException {
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
body.add("grant_type", "authorization_code");
body.add("client_id", kakaoApiKey);
body.add("redirect_uri", "http://localhost:8080/api/users/kakao/callback");
body.add("redirect_uri", "https://hhive.shop/api/users/kakao/callback");
body.add("code", code);

RequestEntity<MultiValueMap<String, String>> requestEntity = RequestEntity
Expand Down

0 comments on commit a333ea5

Please sign in to comment.