Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Oauth 연령, 생일, 전화번호 추가 #28

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public UserInfo toEntity(SocialType socialType, OAuth2UserInfo oauth2UserInfo) {
.socialType(socialType)
.socialId(oauth2UserInfo.getId())
.email(oauth2UserInfo.getEmail())
.phone(oauth2UserInfo.getPhoneNumber())
.age(oauth2UserInfo.getAge())
.birth(oauth2UserInfo.getBirth())
.nickName(oauth2UserInfo.getNickName())
.imageUrl(oauth2UserInfo.getImageUrl())
.role(Role.USER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,37 @@ public String getEmail() {

return (String)account.get("email");
}

@Override
public String getPhoneNumber() {
Map<String, Object> account = (Map<String, Object>)attributes.get("kakao_account");

if (account == null) {
return null;
}

return (String)account.get("phone_number");
}

@Override
public String getBirth() {
Map<String, Object> account = (Map<String, Object>)attributes.get("kakao_account");

if (account == null) {
return null;
}

return (String)account.get("birthyear");
}

@Override
public String getAge() {
Map<String, Object> account = (Map<String, Object>)attributes.get("kakao_account");

if (account == null) {
return null;
}

return (String)account.get("age_range");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ public OAuth2UserInfo(Map<String, Object> attributes) {
public abstract String getImageUrl();

public abstract String getEmail();

public abstract String getPhoneNumber();

public abstract String getBirth();

public abstract String getAge();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public String jwtTest() {
@GetMapping("/auth")
public UserAuthRes userAuth(@AuthenticationPrincipal CustomUserDetails userDetails) {
// 서비스 계층을 호출하여 사용자 정보를 조회합니다.
return userServiceImpl.getUserAuthById(userDetails);
return userServiceImpl.getUserAuthByCustomUserDetails(userDetails);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import jakarta.servlet.http.HttpServletResponse;

public interface UserService {
UserAuthRes getUserAuthById(CustomUserDetails userDetails);
UserAuthRes getUserAuthByCustomUserDetails(CustomUserDetails userDetails);

UserInfoRes getUserInfoById(Long id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class UserServiceImpl implements UserService {
private String refreshCookie;

@Override
public UserAuthRes getUserAuthById(CustomUserDetails userDetails) {
public UserAuthRes getUserAuthByCustomUserDetails(CustomUserDetails userDetails) {

return userMapper.userInfoToUserAuthRes(userDetails);

Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ spring.datasource.url=jdbc:mysql://localhost:3306/readyvery
spring.datasource.username=root
spring.datasource.password=12345678
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
spring.jackson.serialization.fail-on-empty-beans=false
# JWT Configuration
Expand All @@ -12,12 +13,12 @@ jwt.refresh.expiration=604800
jwt.refresh.cookie=refreshToken
jwt.redirect-uri=http://localhost:3000/login
# Kakao
spring.security.oauth2.client.registration.kakao.client-id=e35c097c37d24f762290ec7e9e81887b
spring.security.oauth2.client.registration.kakao.client-secret=bMT73UM5sM7xfB5yulXMtsxPtjmsJfGS
spring.security.oauth2.client.registration.kakao.client-id=f5153d4ff1ef221bc332da3ccfec5e81
spring.security.oauth2.client.registration.kakao.client-secret=E1YuDOXrG22kymEaB53kqRYvMJrt4z5f
spring.security.oauth2.client.registration.kakao.redirect-uri=http://localhost:8080/login/oauth2/code/kakao
spring.security.oauth2.client.registration.kakao.client-authentication-method=client_secret_post
spring.security.oauth2.client.registration.kakao.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.kakao.scope=profile_nickname, profile_image, account_email
spring.security.oauth2.client.registration.kakao.scope=profile_nickname, profile_image, account_email, phone_number, age_range, birthday
spring.security.oauth2.client.registration.kakao.client-name=Kakao
spring.security.oauth2.client.provider.kakao.authorization-uri=https://kauth.kakao.com/oauth/authorize
spring.security.oauth2.client.provider.kakao.token-uri=https://kauth.kakao.com/oauth/token
Expand Down