-
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.
기존의 AuthService 명칭 SocialService로 변경 토큰 재발급 API 구현 Related to: #13
- Loading branch information
1 parent
d081307
commit 916c272
Showing
12 changed files
with
134 additions
and
66 deletions.
There are no files selected for viewing
46 changes: 39 additions & 7 deletions
46
src/main/java/io/sobok/SobokSobok/auth/application/AuthService.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 |
---|---|---|
@@ -1,13 +1,45 @@ | ||
package io.sobok.SobokSobok.auth.application; | ||
|
||
import io.sobok.SobokSobok.auth.ui.dto.SocialLoginRequest; | ||
import io.sobok.SobokSobok.auth.ui.dto.SocialLoginResponse; | ||
import io.sobok.SobokSobok.auth.ui.dto.SocialSignupRequest; | ||
import io.sobok.SobokSobok.auth.ui.dto.SocialSignupResponse; | ||
import io.sobok.SobokSobok.auth.infrastructure.UserRepository; | ||
import io.sobok.SobokSobok.auth.ui.dto.JwtTokenResponse; | ||
import io.sobok.SobokSobok.exception.ErrorCode; | ||
import io.sobok.SobokSobok.exception.model.NotFoundException; | ||
import io.sobok.SobokSobok.security.jwt.Jwt; | ||
import io.sobok.SobokSobok.security.jwt.JwtProvider; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.core.ValueOperations; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
public abstract class AuthService { | ||
@Service | ||
@RequiredArgsConstructor | ||
public class AuthService { | ||
|
||
public abstract SocialSignupResponse signup(SocialSignupRequest request); | ||
private final UserRepository userRepository; | ||
|
||
public abstract SocialLoginResponse login(SocialLoginRequest request); | ||
private final RedisTemplate<String, String> redisTemplate; | ||
private final JwtProvider jwtProvider; | ||
|
||
@Transactional | ||
public JwtTokenResponse refresh(String refresh) { | ||
|
||
ValueOperations<String, String> valueOperations = redisTemplate.opsForValue(); | ||
String socialId = valueOperations.get(refresh); | ||
|
||
if (socialId == null) { | ||
throw new NotFoundException(ErrorCode.UNREGISTERED_TOKEN); | ||
} | ||
|
||
if(!userRepository.existsBySocialInfoSocialId(socialId)) { | ||
throw new NotFoundException(ErrorCode.UNREGISTERED_USER); | ||
} | ||
|
||
Jwt jwt = jwtProvider.getUserJwt(socialId); | ||
|
||
return JwtTokenResponse.builder() | ||
.accessToken(jwt.accessToken()) | ||
.refreshToken(jwt.refreshToken()) | ||
.build(); | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
src/main/java/io/sobok/SobokSobok/auth/application/AuthServiceProvider.java
This file was deleted.
Oops, something went wrong.
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
10 changes: 10 additions & 0 deletions
10
src/main/java/io/sobok/SobokSobok/auth/application/SocialService.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,10 @@ | ||
package io.sobok.SobokSobok.auth.application; | ||
|
||
import io.sobok.SobokSobok.auth.ui.dto.*; | ||
|
||
public abstract class SocialService { | ||
|
||
public abstract SocialSignupResponse signup(SocialSignupRequest request); | ||
|
||
public abstract SocialLoginResponse login(SocialLoginRequest request); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/io/sobok/SobokSobok/auth/application/SocialServiceProvider.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,27 @@ | ||
package io.sobok.SobokSobok.auth.application; | ||
|
||
import io.sobok.SobokSobok.auth.domain.SocialType; | ||
import jakarta.annotation.PostConstruct; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class SocialServiceProvider { | ||
|
||
private static final Map<SocialType, SocialService> socialServiceMap = new HashMap<>(); | ||
|
||
private final KakaoSocialService kakaoSocialService; | ||
|
||
@PostConstruct | ||
void initializeSocialServiceMap() { | ||
socialServiceMap.put(SocialType.KAKAO, kakaoSocialService); | ||
} | ||
|
||
public SocialService getSocialService(SocialType socialType) { | ||
return socialServiceMap.get(socialType); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/io/sobok/SobokSobok/auth/ui/dto/JwtTokenResponse.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,11 @@ | ||
package io.sobok.SobokSobok.auth.ui.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record JwtTokenResponse( | ||
|
||
String accessToken, | ||
|
||
String refreshToken | ||
) { } |
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