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

[Deploy] 프론트 연동을 위한 코드 수정 #79

Merged
merged 5 commits into from
May 3, 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
2 changes: 2 additions & 0 deletions src/main/java/com/jisungin/api/oauth/AuthInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
Long userId = Optional.ofNullable(session.getAttribute(JSESSION_ID))
.map(id -> (Long) id)
.orElseThrow(() -> new BusinessException(UNAUTHORIZED_REQUEST));
log.info("JSESSION_ID 조회 = {}", userId);
authContext.setUserId(userId);
return true;
}
Expand All @@ -63,6 +64,7 @@ private boolean isAuthenticationNotRequired(HttpServletRequest request) {
}

private HttpSession getSession(HttpServletRequest request) {
log.info("세션 조회");
HttpSession session = request.getSession(false);

if (session == null) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/jisungin/api/oauth/OauthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import static com.jisungin.api.oauth.AuthConstant.*;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/oauth")
Expand All @@ -25,6 +27,7 @@ public ApiResponse<Void> redirectAuthRequestUrl(
@PathVariable OauthType oauthType,
HttpServletResponse response
) {
log.info("redirect 요청");
String redirectUrl = oauthService.getAuthCodeRequestUrl(oauthType);
response.sendRedirect(redirectUrl);
return ApiResponse.ok(null);
Expand All @@ -36,9 +39,11 @@ public ApiResponse<Void> login(
@RequestParam("code") String code,
HttpServletRequest request
) {
log.info("login 요청");
Long userId = oauthService.login(oauthType, code);
HttpSession session = request.getSession(true);
session.setAttribute(JSESSION_ID, userId);
log.info("JSESSION_ID = {}", session.getAttribute(JSESSION_ID));
return ApiResponse.ok(null);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jisungin/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000")
.allowedOrigins("http://localhost:3000", "https://api.jisungin.co.kr")
.allowedMethods(
HttpMethod.GET.name(),
HttpMethod.POST.name(),
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ spring:
include:
- oauth
- crawler
- s3
- s3

server:
servlet:
session:
cookie:
same-site: none
secure: true
Loading