-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #187 from gunsight1/feature_member_for_kakao
feature :: 카카오 로그인
- Loading branch information
Showing
12 changed files
with
128 additions
and
13 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
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
16 changes: 16 additions & 0 deletions
16
module-api/src/main/java/com/kernel360/member/dto/KakaoUserDto.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,16 @@ | ||
package com.kernel360.member.dto; | ||
|
||
public record KakaoUserDto( | ||
String id, | ||
String email | ||
) { | ||
public static KakaoUserDto of( | ||
String id, | ||
String email | ||
){ | ||
return new KakaoUserDto( | ||
id, | ||
); | ||
} | ||
} |
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
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
47 changes: 47 additions & 0 deletions
47
module-api/src/main/java/com/kernel360/member/service/KakaoRequest.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,47 @@ | ||
package com.kernel360.member.service; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.kernel360.exception.BusinessException; | ||
import com.kernel360.member.code.MemberErrorCode; | ||
import com.kernel360.member.dto.KakaoUserDto; | ||
import org.springframework.http.*; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Component | ||
public class KakaoRequest { | ||
|
||
public KakaoUserDto getKakaoUserByToken(String accessToken) { | ||
|
||
String url = "https://kapi.kakao.com/v2/user/me"; | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
|
||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); | ||
headers.set("Authorization", "Bearer "+accessToken); | ||
headers.set("charset", "utf-8"); | ||
|
||
HttpEntity<String> requestEntity = new HttpEntity<>(headers); | ||
RestTemplate restTemplate = new RestTemplate(); | ||
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class); | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
Map<String, Object> kakaoResponse; | ||
|
||
try { | ||
kakaoResponse = mapper.readValue(responseEntity.getBody(), HashMap.class); | ||
}catch (Exception e){ | ||
throw new BusinessException(MemberErrorCode.FAILED_REQUEST_LOGIN_FOR_KAKAO); | ||
} | ||
Map<String, Object> kakaoAccount = mapper.convertValue(kakaoResponse.get("kakao_account"), HashMap.class); | ||
|
||
KakaoUserDto dto = KakaoUserDto.of(kakaoResponse.get("id").toString(),kakaoAccount.get("email").toString()); | ||
|
||
return dto; | ||
} | ||
|
||
|
||
} |
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
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 |
---|---|---|
|
@@ -31,7 +31,7 @@ class MemberControllerTest extends ControllerTest { | |
void 회원가입요청() throws Exception { | ||
|
||
/** given 목데이터 세팅 **/ | ||
MemberDto memberDto = MemberDto.of("testID", "[email protected]", "testPassword", "man", "30"); | ||
MemberDto memberDto = MemberDto.of("testID", "[email protected]", "testPassword", "MALE", "30"); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
String param = objectMapper.writeValueAsString(memberDto); | ||
|
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