-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
26 changed files
with
174 additions
and
43 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
1 change: 0 additions & 1 deletion
1
src/main/java/com/tecst/tecst/domain/common_question/entity/CommonQuestion.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
4 changes: 3 additions & 1 deletion
4
src/main/java/com/tecst/tecst/domain/oauth/client/ClientKakao.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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/tecst/tecst/domain/oauth/client/ClientProxy.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
14 changes: 3 additions & 11 deletions
14
src/main/java/com/tecst/tecst/domain/oauth/config/SecurityConfig.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
27 changes: 26 additions & 1 deletion
27
src/main/java/com/tecst/tecst/domain/oauth/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,2 +1,27 @@ | ||
package com.tecst.tecst.domain.oauth.controller;public class OauthController { | ||
package com.tecst.tecst.domain.oauth.controller; | ||
|
||
import com.tecst.tecst.domain.oauth.dto.ApiResponse; | ||
import com.tecst.tecst.domain.oauth.dto.AuthRequest; | ||
import com.tecst.tecst.domain.oauth.dto.AuthResponse; | ||
import com.tecst.tecst.domain.oauth.jwt.AuthTokenProvider; | ||
import com.tecst.tecst.domain.oauth.service.KakaoAuthService; | ||
import io.swagger.annotations.ApiOperation; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/auth") | ||
@RequiredArgsConstructor | ||
public class OauthController { | ||
private final KakaoAuthService kakaoAuthService; | ||
private final AuthTokenProvider authTokenProvider; | ||
|
||
@ApiOperation(value = "카카오 로그인", notes = "카카오 엑세스 토큰을 이용하여 사용자 정보 받아 저장하고 앱의 토큰 신환") | ||
@PostMapping(value = "/kakao") | ||
public ResponseEntity<AuthResponse> kakaoAuthRequest(@RequestBody AuthRequest authRequest) { | ||
return ApiResponse.success(kakaoAuthService.login(authRequest)); | ||
} | ||
} |
27 changes: 25 additions & 2 deletions
27
src/main/java/com/tecst/tecst/domain/oauth/dto/ApiResponse.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,2 +1,25 @@ | ||
package com.tecst.tecst.domain.oauth.dto;public class ApiResponse { | ||
} | ||
package com.tecst.tecst.domain.oauth.dto; | ||
|
||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@Getter | ||
public class ApiResponse<T> { | ||
|
||
public static <T> ResponseEntity<T> success(T body) { | ||
return ResponseEntity.status(HttpStatus.OK).body(body); | ||
} | ||
|
||
public static <T> ResponseEntity<T> created(T body) { | ||
return ResponseEntity.status(HttpStatus.CREATED).body(body); | ||
} | ||
|
||
public static <T> ResponseEntity<T> fail(T body) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(body); | ||
} | ||
|
||
public static <T> ResponseEntity<T> forbidden(T body) { | ||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(body); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/tecst/tecst/domain/oauth/dto/AuthRequest.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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/tecst/tecst/domain/oauth/dto/AuthResponse.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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/tecst/tecst/domain/oauth/dto/KakaoUserResponse.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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/tecst/tecst/domain/oauth/enumerate/RoleType.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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/tecst/tecst/domain/oauth/exception/TokenValidFailedException.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
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
3 changes: 2 additions & 1 deletion
3
src/main/java/com/tecst/tecst/domain/oauth/jwt/AuthTokenProvider.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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/tecst/tecst/domain/oauth/jwt/JwtAuthenticationFilter.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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/tecst/tecst/domain/oauth/jwt/JwtHeaderUtil.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
45 changes: 43 additions & 2 deletions
45
src/main/java/com/tecst/tecst/domain/oauth/service/KakaoAuthService.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,2 +1,43 @@ | ||
package com.tecst.tecst.domain.oauth.service;public class KakaoAuthService { | ||
} | ||
package com.tecst.tecst.domain.oauth.service; | ||
|
||
import com.tecst.tecst.domain.oauth.client.ClientKakao; | ||
import com.tecst.tecst.domain.oauth.dto.AuthRequest; | ||
import com.tecst.tecst.domain.oauth.dto.AuthResponse; | ||
import com.tecst.tecst.domain.oauth.jwt.AuthToken; | ||
import com.tecst.tecst.domain.oauth.jwt.AuthTokenProvider; | ||
import com.tecst.tecst.domain.user.entity.User; | ||
import com.tecst.tecst.domain.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class KakaoAuthService { | ||
|
||
private final ClientKakao clientKakao; | ||
private final AuthTokenProvider authTokenProvider; | ||
private final UserRepository userRepository; | ||
|
||
@Transactional | ||
public AuthResponse login(AuthRequest authRequest) { | ||
User kakaoMember = clientKakao.getUserData(authRequest.getAccessToken()); | ||
String socialId = kakaoMember.getEmail(); | ||
User member = userRepository.findByEmail(socialId); | ||
|
||
AuthToken appToken = authTokenProvider.createUserAppToken(socialId); | ||
|
||
if (member == null) { | ||
userRepository.save(kakaoMember); | ||
return AuthResponse.builder() | ||
.appToken(appToken.getToken()) | ||
.isNewUser(Boolean.TRUE) | ||
.build(); | ||
} | ||
|
||
return AuthResponse.builder() | ||
.appToken(appToken.getToken()) | ||
.isNewUser(Boolean.FALSE) | ||
.build(); | ||
} | ||
} |
40 changes: 39 additions & 1 deletion
40
src/main/java/com/tecst/tecst/domain/oauth/service/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 |
---|---|---|
@@ -1,2 +1,40 @@ | ||
package com.tecst.tecst.domain.oauth.service;public class OauthService { | ||
package com.tecst.tecst.domain.oauth.service; | ||
|
||
import com.tecst.tecst.domain.oauth.client.ClientKakao; | ||
import com.tecst.tecst.domain.oauth.dto.AuthRequest; | ||
import com.tecst.tecst.domain.oauth.dto.AuthResponse; | ||
import com.tecst.tecst.domain.oauth.jwt.AuthToken; | ||
import com.tecst.tecst.domain.oauth.jwt.AuthTokenProvider; | ||
import com.tecst.tecst.domain.user.entity.User; | ||
import com.tecst.tecst.domain.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class OauthService { | ||
|
||
private final UserRepository userRepository; | ||
private final ClientKakao clientKakao; | ||
private final AuthTokenProvider authTokenProvider; | ||
|
||
@Transactional | ||
public AuthResponse login(AuthRequest authRequest) { | ||
User kakaoMember = clientKakao.getUserData(authRequest.getAccessToken()); | ||
String email = kakaoMember.getEmail(); | ||
User user = userRepository.findByEmail(email); | ||
|
||
AuthToken appToken = authTokenProvider.createUserAppToken(email); | ||
|
||
if (user == null) { | ||
userRepository.save(kakaoMember); | ||
} | ||
|
||
return AuthResponse.builder() | ||
.appToken(appToken.getToken()) | ||
.build(); | ||
} | ||
} |
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
Empty file.
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