-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97e52e4
commit 21a9463
Showing
47 changed files
with
383 additions
and
191 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
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
7 changes: 0 additions & 7 deletions
7
src/main/java/com/kcy/fitapet/domain/oauth/dao/OAuthRepository.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/main/java/com/kcy/fitapet/domain/oauth/dao/OauthRepository.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,13 @@ | ||
package com.kcy.fitapet.domain.oauth.dao; | ||
|
||
import com.kcy.fitapet.domain.oauth.domain.OauthAccount; | ||
import com.kcy.fitapet.domain.oauth.type.ProviderType; | ||
import com.kcy.fitapet.global.common.repository.ExtendedRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface OauthRepository extends ExtendedRepository<OauthAccount, Long> { | ||
Optional<OauthAccount> findByOauthIdAndProvider(Long oauthId, ProviderType provider); | ||
boolean existsByOauthIdAndProvider(Long oauthId, ProviderType provider); | ||
boolean existsByEmail(String email); | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/kcy/fitapet/domain/oauth/exception/OauthException.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,25 @@ | ||
package com.kcy.fitapet.domain.oauth.exception; | ||
|
||
import com.kcy.fitapet.global.common.response.code.StatusCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum OauthException implements StatusCode { | ||
/* BAD REQUEST */ | ||
INVALID_PROVIDER(HttpStatus.BAD_REQUEST, "유효하지 않은 제공자입니다."), | ||
|
||
/* FORBIDDEN */ | ||
NOT_FOUND_MEMBER(HttpStatus.FORBIDDEN, "존재하지 않는 회원입니다."); | ||
|
||
private final HttpStatus httpStatus; | ||
private final String message; | ||
|
||
|
||
@Override | ||
public String getName() { | ||
return name(); | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
src/main/java/com/kcy/fitapet/domain/oauth/service/OAuthService.java
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
src/main/java/com/kcy/fitapet/domain/oauth/service/component/OauthService.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,72 @@ | ||
package com.kcy.fitapet.domain.oauth.service.component; | ||
|
||
import com.kcy.fitapet.domain.member.domain.Member; | ||
import com.kcy.fitapet.domain.oauth.service.module.OauthApplicationConfigHelper; | ||
import com.kcy.fitapet.domain.oauth.service.module.OauthClientHelper; | ||
import com.kcy.fitapet.domain.oauth.service.module.OauthSearchService; | ||
import com.kcy.fitapet.domain.oauth.type.ProviderType; | ||
import com.kcy.fitapet.global.common.security.jwt.JwtUtil; | ||
import com.kcy.fitapet.global.common.security.jwt.dto.Jwt; | ||
import com.kcy.fitapet.global.common.security.jwt.dto.JwtUserInfo; | ||
import com.kcy.fitapet.global.common.security.oauth.OauthApplicationConfig; | ||
import com.kcy.fitapet.global.common.security.oauth.OauthClient; | ||
import com.kcy.fitapet.global.common.security.oauth.OauthOIDCHelper; | ||
import com.kcy.fitapet.global.common.security.oauth.dto.OIDCDecodePayload; | ||
import com.kcy.fitapet.global.common.security.oauth.dto.OIDCPublicKeyResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class OauthService { | ||
private final OauthSearchService oauthSearchService; | ||
|
||
private final OauthOIDCHelper oauthOIDCHelper; | ||
private final OauthClientHelper oauthClientHelper; | ||
private final OauthApplicationConfigHelper oauthApplicationConfigHelper; | ||
|
||
private final JwtUtil jwtUtil; | ||
|
||
@Transactional | ||
public void signUpByOIDC() { | ||
|
||
} | ||
|
||
@Transactional | ||
public Jwt signInByOIDC(String id, String idToken, ProviderType provider, String nonce) { | ||
OauthClient oauthClient = oauthClientHelper.getOauthClient(provider); | ||
OIDCPublicKeyResponse oidcPublicKeyResponse = oauthClient.getOIDCPublicKey(); | ||
OauthApplicationConfig oauthApplicationConfig = oauthApplicationConfigHelper.getOauthApplicationConfig(provider); | ||
|
||
OIDCDecodePayload payload = oauthOIDCHelper.getPayloadFromIdToken( | ||
idToken, oauthApplicationConfig.getAuthorizationUri(), | ||
oauthApplicationConfig.getClientId(), nonce, oidcPublicKeyResponse); | ||
|
||
if (oauthSearchService.isExistMember(Long.parseLong(payload.sub()), provider)) { | ||
Member member = oauthSearchService.findMemberByOauthIdAndProvider(Long.parseLong(payload.sub()), provider); | ||
return generateToken(JwtUserInfo.from(member)); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Transactional | ||
public void signInByCode() { | ||
|
||
} | ||
|
||
@Transactional | ||
public void signUpByCode() { | ||
|
||
} | ||
|
||
private Jwt generateToken(JwtUserInfo jwtUserInfo) { | ||
return Jwt.builder() | ||
.accessToken(jwtUtil.generateAccessToken(jwtUserInfo)) | ||
.refreshToken(jwtUtil.generateRefreshToken(jwtUserInfo)) | ||
.build(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/kcy/fitapet/domain/oauth/service/module/OauthApplicationConfigHelper.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,25 @@ | ||
package com.kcy.fitapet.domain.oauth.service.module; | ||
|
||
import com.kcy.fitapet.domain.oauth.exception.OauthException; | ||
import com.kcy.fitapet.domain.oauth.type.ProviderType; | ||
import com.kcy.fitapet.global.common.response.exception.GlobalErrorException; | ||
import com.kcy.fitapet.global.common.security.oauth.OauthApplicationConfig; | ||
import com.kcy.fitapet.global.common.security.oauth.kakao.KakaoApplicationConfig; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class OauthApplicationConfigHelper { | ||
private final KakaoApplicationConfig kakaoApplicationConfig; | ||
|
||
public OauthApplicationConfig getOauthApplicationConfig(ProviderType provider) { | ||
return switch (provider) { | ||
case KAKAO -> kakaoApplicationConfig; | ||
case GOOGLE -> null; | ||
case APPLE -> null; | ||
case NAVER -> null; | ||
default -> throw new GlobalErrorException(OauthException.INVALID_PROVIDER); | ||
}; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/kcy/fitapet/domain/oauth/service/module/OauthClientHelper.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,24 @@ | ||
package com.kcy.fitapet.domain.oauth.service.module; | ||
|
||
import com.kcy.fitapet.domain.oauth.exception.OauthException; | ||
import com.kcy.fitapet.domain.oauth.type.ProviderType; | ||
import com.kcy.fitapet.global.common.response.exception.GlobalErrorException; | ||
import com.kcy.fitapet.global.common.security.oauth.OauthClient; | ||
import com.kcy.fitapet.global.common.security.oauth.kakao.KakaoOauthClient; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class OauthClientHelper { | ||
private final KakaoOauthClient kakaoOauthClient; | ||
|
||
public OauthClient getOauthClient(ProviderType provider) { | ||
return switch (provider) { | ||
case KAKAO -> kakaoOauthClient; | ||
case GOOGLE -> null; | ||
case APPLE -> null; | ||
default -> throw new GlobalErrorException(OauthException.INVALID_PROVIDER); | ||
}; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/kcy/fitapet/domain/oauth/service/module/OauthSearchService.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,34 @@ | ||
package com.kcy.fitapet.domain.oauth.service.module; | ||
|
||
import com.kcy.fitapet.domain.member.domain.Member; | ||
import com.kcy.fitapet.domain.oauth.dao.OauthRepository; | ||
import com.kcy.fitapet.domain.oauth.domain.OauthAccount; | ||
import com.kcy.fitapet.domain.oauth.exception.OauthException; | ||
import com.kcy.fitapet.domain.oauth.type.ProviderType; | ||
import com.kcy.fitapet.global.common.response.exception.GlobalErrorException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class OauthSearchService { | ||
private final OauthRepository oauthRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public boolean isExistMember(Long oauthId, ProviderType provider) { | ||
return oauthRepository.existsByOauthIdAndProvider(oauthId, provider); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public boolean isExistEmail(String email) { | ||
return oauthRepository.existsByEmail(email); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public Member findMemberByOauthIdAndProvider(Long oauthId, ProviderType provider) { | ||
OauthAccount oauthAccount = oauthRepository.findByOauthIdAndProvider(oauthId, provider) | ||
.orElseThrow(() -> new GlobalErrorException(OauthException.NOT_FOUND_MEMBER)); | ||
return oauthAccount.getMember(); | ||
} | ||
} |
Oops, something went wrong.