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

RAC-422 feat : 토큰 기반 로그인 추가 #310

Merged
merged 2 commits into from
Aug 17, 2024
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
@@ -0,0 +1,4 @@
package com.postgraduate.domain.auth.application.dto.req;

public record TokenRequest(String accessToken) {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.postgraduate.domain.auth.application.usecase.oauth;

import com.postgraduate.domain.auth.application.dto.req.CodeRequest;
import com.postgraduate.domain.auth.application.dto.req.TokenRequest;
import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse;

public interface SignInUseCase {
AuthUserResponse getUser(CodeRequest request);

AuthUserResponse getDevUser(CodeRequest codeRequest);

AuthUserResponse getUserWithToken(TokenRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private KakaoUserInfoResponse getKakaoUserInfoResponse(MultiValueMap<String, Str
}
}

private KakaoUserInfoResponse getUserInfo(String accessToken) {
public KakaoUserInfoResponse getUserInfo(String accessToken) {
try {
return webClient.get()
.uri(USER_INFO_URI)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.postgraduate.domain.auth.application.usecase.oauth.kakao;

import com.postgraduate.domain.auth.application.dto.req.CodeRequest;
import com.postgraduate.domain.auth.application.dto.req.TokenRequest;
import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse;
import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse;
import com.postgraduate.domain.auth.application.mapper.AuthMapper;
Expand All @@ -12,12 +13,14 @@
import com.postgraduate.domain.user.user.exception.UserNotFoundException;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional
@Slf4j
public class KakaoSignInUseCase implements SignInUseCase {
private final KakaoAccessTokenUseCase kakaoTokenUseCase;
private final UserGetService userGetService;
Expand All @@ -35,11 +38,19 @@ public AuthUserResponse getDevUser(CodeRequest codeRequest) {
return getAuthUserResponse(userInfo);
}

@Override
public AuthUserResponse getUserWithToken(TokenRequest request) {
KakaoUserInfoResponse userInfo = kakaoTokenUseCase.getUserInfo(request.accessToken());
log.info("user : {}", userInfo.id());
return getAuthUserResponse(userInfo);
}

@NotNull
private AuthUserResponse getAuthUserResponse(KakaoUserInfoResponse userInfo) {
Long socialId = userInfo.id();
try {
User user = userGetService.bySocialId(socialId);
log.info("check user {} ", user.getUserId());
checkDelete(user);
return AuthMapper.mapToAuthUser(user, socialId);
} catch (UserNotFoundException e) {
Expand All @@ -50,7 +61,7 @@ private AuthUserResponse getAuthUserResponse(KakaoUserInfoResponse userInfo) {
private void checkDelete(User user) {
if (user.isDelete()) {
if (user.isRealDelete())
throw new DeletedUserException();
throw new DeletedUserException(); //todo : 다시 탈퇴 처리 필요 (카카오 계정과 끊기)
userUpdateService.updateRestore(user);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public class AuthController {
private final QuitManageUseCase quitManageUseCase;
private final JwtUseCase jwtUseCase;

@PostMapping("/login/token/{provider}")
@Operation(summary = "소셜 로그인", description = "회원인 경우 JWT를, 회원이 아닌 경우 socialId를 반환합니다(회원가입은 진행하지 않습니다).")
public ResponseEntity<ResponseDto<AuthResponse>> authLoginWithToken(@RequestBody @Valid TokenRequest request, @PathVariable Provider provider) {
SignInUseCase signInUseCase = selectOauth.selectSignIn(provider);
AuthUserResponse authUser = signInUseCase.getUserWithToken(request);
if (authUser.user() == null)
return ResponseEntity.ok(create(AUTH_NONE.getCode(), NOT_REGISTERED_USER.getMessage(), authUser));
JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.user());
return ResponseEntity.ok(create(AUTH_ALREADY.getCode(), SUCCESS_AUTH.getMessage(), jwtToken));
}

@PostMapping("/login/{provider}")
@Operation(summary = "소셜 로그인", description = "회원인 경우 JWT를, 회원이 아닌 경우 socialId를 반환합니다(회원가입은 진행하지 않습니다).")
public ResponseEntity<ResponseDto<AuthResponse>> authLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ public class BizppurioSend {
private final ObjectMapper objectMapper;
private final WebClient webClient;
private final SlackErrorMessage slackErrorMessage;
private static final String DEV = "DEV";

@Value("${bizppurio.message}")
private String messageUrl;
@Value("${bizppurio.status}")
private String status;

protected void sendMessageWithExceptionHandling(Supplier<CommonRequest> messageSupplier) {
if (status.equals(DEV))
return;
try {
CommonRequest commonRequest = messageSupplier.get();
String accessToken = bizppurioAuth.getAuth();
Expand Down
Loading