Skip to content

Commit

Permalink
Merge pull request #24 from 9oormthon-univ/feature/GOORM-2-kakao-login
Browse files Browse the repository at this point in the history
[GOORM-2]-access token값으로 kakao user Id 값 조회
  • Loading branch information
Junghs21 authored Nov 23, 2024
2 parents 3a046bc + d16f5d2 commit 6c8c62e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,11 @@ public User saveOrUpdateUser(UserInfoResponseDto userInfo) {
return userRepository.save(user);
}

public Long getKakaoUserIdFromAccessToken(String accessToken) {

UserInfoResponseDto userInfo = getUserInfo(accessToken);
Long kakaoUserId = userInfo.getId();

return kakaoUserId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,18 @@ public ResponseEntity<?> saveUserInfo(@RequestHeader("Authorization") String aut

return ResponseEntity.ok(response);
}

@GetMapping("/kakao-user-id")
public ResponseEntity<?> getKakaoUserId(@RequestHeader("Authorization") String authorization) {

if (authorization == null || !authorization.startsWith("Bearer ")) {
return new ResponseEntity<>("Missing or invalid Authorization header", HttpStatus.UNAUTHORIZED);
}

String accessToken = authorization.substring(7);
Long kakaoUserId = userLoginService.getKakaoUserIdFromAccessToken(accessToken);

return ResponseEntity.ok(Map.of("kakao_user_id", kakaoUserId));
}

}

0 comments on commit 6c8c62e

Please sign in to comment.