Skip to content

Commit

Permalink
Merge pull request #79 from jisung-in/deploy/78-front-connection
Browse files Browse the repository at this point in the history
[Deploy] 프론트 연동을 위한 코드 수정
  • Loading branch information
pdohyung authored May 3, 2024
2 parents b3ceb5c + 73bf9ff commit aab918d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
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

0 comments on commit aab918d

Please sign in to comment.