-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from AR-TTUBEOG/feature/8
[Feat] 카카오 로그인 구체화
- Loading branch information
Showing
22 changed files
with
164 additions
and
614 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
74 changes: 0 additions & 74 deletions
74
src/main/java/com/ttubeog/domain/auth/application/CustomDefaultOAuth2UserService.java
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
src/main/java/com/ttubeog/domain/auth/application/CustomMemberDetailsService.java
This file was deleted.
Oops, something went wrong.
135 changes: 0 additions & 135 deletions
135
src/main/java/com/ttubeog/domain/auth/application/CustomTokenProviderService.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
39 changes: 35 additions & 4 deletions
39
src/main/java/com/ttubeog/domain/auth/controller/OauthController.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,30 +1,61 @@ | ||
package com.ttubeog.domain.auth.controller; | ||
|
||
import com.ttubeog.domain.auth.application.OauthService; | ||
import com.ttubeog.domain.auth.dto.OauthRequestDto; | ||
import com.ttubeog.domain.auth.dto.OauthResponseDto; | ||
import com.ttubeog.domain.auth.dto.RefreshTokenResponseDto; | ||
import com.ttubeog.domain.auth.service.OauthService; | ||
import com.ttubeog.global.error.DefaultException; | ||
import com.ttubeog.global.payload.ErrorCode; | ||
import jakarta.servlet.http.Cookie; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/auth") | ||
public class OauthController { | ||
private final OauthService oauthService; | ||
|
||
// 카카오 로그인 | ||
@PostMapping("/auth/login/kakao") | ||
@PostMapping("/login/kakao") | ||
public OauthResponseDto loginWithKaKao( | ||
@RequestBody | ||
OauthRequestDto oauthRequestDto, | ||
HttpServletResponse response | ||
) { | ||
OauthResponseDto oauthResponseDto = new OauthResponseDto(); | ||
String accessToken = oauthService.loginWithKakao(oauthResponseDto.getAccessToken(), response); | ||
String accessToken = oauthService.loginWithKakao(oauthRequestDto.getAccessToken(), response); | ||
oauthResponseDto.setAccessToken(accessToken); | ||
return oauthResponseDto; | ||
} | ||
|
||
// 리프레시 토큰으로 액세스토큰 재발급 | ||
@PostMapping("/token/refresh") | ||
public RefreshTokenResponseDto tokenRefresh(HttpServletRequest request) { | ||
RefreshTokenResponseDto refreshTokenResponseDto = new RefreshTokenResponseDto(); | ||
Cookie[] list = request.getCookies(); | ||
|
||
if (list == null) { | ||
throw new DefaultException(ErrorCode.INVALID_CHECK); | ||
} | ||
|
||
Cookie refreshTokenCookie = Arrays.stream(list).filter(cookie -> | ||
cookie.getName().equals("refresh_token")).collect(Collectors.toList()).get(0); | ||
|
||
if (refreshTokenCookie == null) { | ||
throw new DefaultException(ErrorCode.INVALID_CHECK); | ||
} | ||
|
||
String accessToken = oauthService.refreshToAccessToken(refreshTokenCookie.getValue()); | ||
refreshTokenResponseDto.setAccessToken(accessToken); | ||
return refreshTokenResponseDto; | ||
} | ||
} |
Oops, something went wrong.