-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'weekly_11' into feat/58/get-my-orders
- Loading branch information
Showing
19 changed files
with
207 additions
and
54 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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/ordertogether/team14_be/auth/application/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,19 +1,35 @@ | ||
package com.ordertogether.team14_be.auth.application.service; | ||
|
||
import com.ordertogether.team14_be.auth.application.dto.KakaoUserInfo; | ||
import com.ordertogether.team14_be.auth.persistence.JwtUtil; | ||
import com.ordertogether.team14_be.auth.presentation.KakaoClient; | ||
import com.ordertogether.team14_be.member.application.service.MemberService; | ||
import com.ordertogether.team14_be.member.persistence.entity.Member; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class KakaoAuthService { | ||
private final KakaoClient kakaoClient; | ||
private final MemberService memberService; | ||
private final JwtUtil jwtUtil; | ||
private static final String LOGIN_PLATFORM = "KAKAO"; | ||
private final AuthService authService; | ||
|
||
public String getKakaoUserEmail(String authorizationCode) { | ||
String kakaoToken = kakaoClient.getAccessToken(authorizationCode); | ||
KakaoUserInfo kakaoUserInfo = kakaoClient.getUserInfo((kakaoToken)); | ||
String userKakaoEmail = kakaoUserInfo.kakaoAccount().email(); | ||
return userKakaoEmail; | ||
} | ||
|
||
public String register(String email, String deliveryName, String phoneNumber) { | ||
Member member = new Member(email, 0, phoneNumber, deliveryName, LOGIN_PLATFORM); | ||
authService.validMember(email, LOGIN_PLATFORM); | ||
memberService.registerMember(member); | ||
Long memberId = memberService.getMemberId(email); | ||
String serviceToken = jwtUtil.generateToken(memberId); | ||
return serviceToken; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/ordertogether/team14_be/auth/persistence/JwtInterceptor.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,44 @@ | ||
package com.ordertogether.team14_be.auth.persistence; | ||
|
||
import com.ordertogether.team14_be.member.application.exception.NotFoundMember; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Component | ||
public class JwtInterceptor implements HandlerInterceptor { | ||
private final JwtUtil jwtUtil; | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) | ||
throws Exception { | ||
if (HttpMethod.OPTIONS.matches(request.getMethod())) { | ||
return true; | ||
} | ||
|
||
String authorization = request.getHeader(HttpHeaders.AUTHORIZATION); | ||
String token = authorization.replaceAll("Bearer ", ""); | ||
|
||
if (token != null && token.length() > 10) { | ||
log.debug("토큰 상태:: " + token); | ||
|
||
if (jwtUtil.vaildToken(token)) { | ||
String memberIdString = jwtUtil.decodeJwt(token).getSubject(); | ||
Long memberId = Long.parseLong(memberIdString); | ||
|
||
request.setAttribute("memberId", memberId); | ||
return true; | ||
} | ||
} else { | ||
throw new NotFoundMember(); | ||
} | ||
return false; | ||
} | ||
} |
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: 7 additions & 0 deletions
7
src/main/java/com/ordertogether/team14_be/auth/persistence/exception/AlreadyExistMember.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,7 @@ | ||
package com.ordertogether.team14_be.auth.persistence.exception; | ||
|
||
public class AlreadyExistMember extends RuntimeException { | ||
public AlreadyExistMember() { | ||
super("이미 회원이 존재합니다."); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/ordertogether/team14_be/auth/persistence/exception/InvalidToken.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,7 @@ | ||
package com.ordertogether.team14_be.auth.persistence.exception; | ||
|
||
public class InvalidToken extends IllegalAccessException { | ||
public InvalidToken() { | ||
super("토큰이 유효하지 않습니다."); | ||
} | ||
} |
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
20 changes: 16 additions & 4 deletions
20
src/main/java/com/ordertogether/team14_be/config/WebConfig.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,21 +1,33 @@ | ||
package com.ordertogether.team14_be.config; | ||
|
||
import com.ordertogether.team14_be.auth.persistence.JwtInterceptor; | ||
import com.ordertogether.team14_be.member.application.LoginMemberArgumentResolver; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
@EnableWebMvc | ||
public class WebConfig implements WebMvcConfigurer { | ||
private final LoginMemberArgumentResolver loginMemberArgumentResolver; | ||
|
||
public WebConfig(LoginMemberArgumentResolver loginMemberArgumentResolver) { | ||
this.loginMemberArgumentResolver = loginMemberArgumentResolver; | ||
} | ||
private final JwtInterceptor jwtInterceptor; | ||
|
||
@Override | ||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { | ||
argumentResolvers.add(loginMemberArgumentResolver); | ||
} | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry | ||
.addInterceptor(jwtInterceptor) | ||
.addPathPatterns("/**") | ||
.excludePathPatterns( | ||
"/signup", "/api/v1/auth/signup", "/api/v1/auth/login", "/api/v1/spot/**"); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...main/java/com/ordertogether/team14_be/member/application/LoginMemberArgumentResolver.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
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
Oops, something went wrong.