Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2120626
Authorization feature
johnjal Jan 10, 2025
4c2a6f7
Authentication feature implemented
johnjal Jan 11, 2025
2ce5b38
bug fix
johnjal Jan 11, 2025
a438e4a
fix conflict
johnjal Jan 12, 2025
585ba05
refresh token
johnjal Jan 17, 2025
0c03859
minor issues fixed
johnjal Jan 17, 2025
edb0693
merge
johnjal Jan 22, 2025
629e6ad
google login
johnjal Jan 24, 2025
333d75e
kakao added
johnjal Jan 25, 2025
78c9b70
merge
johnjal Jan 25, 2025
7e96d91
pre merge
johnjal Feb 3, 2025
d09fddd
Merge branch 'Develop' of https://github.com/johnjal/CodePlay-BE into…
johnjal Feb 3, 2025
d1009e7
name attribute deleted
johnjal Feb 6, 2025
76372e6
minor fix
johnjal Feb 6, 2025
7fa4382
conflict resolve
johnjal Feb 9, 2025
1e77ac0
Merge branch 'Develop' of https://github.com/UMC-CodePlay/CodePlay-BE…
johnjal Feb 9, 2025
09aaa97
Merge branch 'Develop' of https://github.com/UMC-CodePlay/CodePlay-BE…
johnjal Feb 12, 2025
2f147c2
Merge branch 'Develop' of https://github.com/UMC-CodePlay/CodePlay-BE…
johnjal Feb 16, 2025
a578b03
Merge branch 'Develop' of https://github.com/UMC-CodePlay/CodePlay-BE…
johnjal Feb 16, 2025
3e0c127
Merge remote-tracking branch 'origin/Develop' into develop
johnjal Feb 18, 2025
9ae497f
sqsfix
johnjal Feb 18, 2025
defdff9
oauthpop
johnjal Feb 20, 2025
ae19c84
Merge branch 'Develop' of https://github.com/UMC-CodePlay/CodePlay-BE…
johnjal Feb 20, 2025
0fa0ede
Merge branch 'develop' into feat-oauthpop
johnjal Feb 20, 2025
3505ad8
frontendurl
johnjal Feb 20, 2025
198eb63
frontendurl
johnjal Feb 20, 2025
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
49 changes: 40 additions & 9 deletions src/main/java/umc/codeplay/controller/OAuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.util.LinkedMultiValueMap;
Expand All @@ -17,15 +18,14 @@
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import umc.codeplay.apiPayLoad.ApiResponse;
import org.jetbrains.annotations.NotNull;
import umc.codeplay.apiPayLoad.code.status.ErrorStatus;
import umc.codeplay.apiPayLoad.exception.handler.GeneralHandler;
import umc.codeplay.config.properties.BaseOAuthProperties;
import umc.codeplay.config.properties.GoogleOAuthProperties;
import umc.codeplay.config.properties.KakaoOAuthProperties;
import umc.codeplay.domain.Member;
import umc.codeplay.domain.enums.SocialStatus;
import umc.codeplay.dto.MemberResponseDTO;
import umc.codeplay.jwt.JwtUtil;
import umc.codeplay.service.MemberService;

Expand All @@ -36,6 +36,9 @@
@Tag(name = "oauth-controller", description = "외부 소셜 로그인 서비스 연동 API, JWT 토큰 헤더 포함을 필요로 하지 않습니다.")
public class OAuthController {

@Value("${frontend.url}")
private static String targetOrigin;

private final JwtUtil jwtUtil;
private final RestTemplate restTemplate = new RestTemplate();
private final GoogleOAuthProperties googleOAuthProperties;
Expand Down Expand Up @@ -65,7 +68,7 @@ public RedirectView redirectToOAuth(@PathVariable("provider") String provider) {

@Hidden
@GetMapping("/callback/{provider}")
public ApiResponse<MemberResponseDTO.LoginResultDTO> OAuthCallback(
public ResponseEntity<String> OAuthCallback(
@RequestParam("code") String code, @PathVariable("provider") String provider) {
BaseOAuthProperties properties =
switch (provider) {
Expand Down Expand Up @@ -110,13 +113,41 @@ public ApiResponse<MemberResponseDTO.LoginResultDTO> OAuthCallback(
String serviceAccessToken = jwtUtil.generateToken(email, authorities);
String serviceRefreshToken = jwtUtil.generateRefreshToken(email, authorities);

String html = getString(serviceAccessToken, serviceRefreshToken, email);

return ResponseEntity.ok().contentType(MediaType.TEXT_HTML).body(html);

// (6) 최종적으로 JWT(액세스/리프레시)를 프론트에 응답
return ApiResponse.onSuccess(
MemberResponseDTO.LoginResultDTO.builder()
.email(email)
.token(serviceAccessToken)
.refreshToken(serviceRefreshToken)
.build());
// return ApiResponse.onSuccess(
// MemberResponseDTO.LoginResultDTO.builder()
// .email(email)
// .token(serviceAccessToken)
// .refreshToken(serviceRefreshToken)
// .build());
}

private static @NotNull String getString(
String serviceAccessToken, String serviceRefreshToken, String email) {
String jsonData =
String.format(
"{ \"accessToken\": \"%s\", \"refreshToken\": \"%s\", \"email\": \"%s\" }",
serviceAccessToken, serviceRefreshToken, email);

return """
<!DOCTYPE html>
<html>
<body>
<script>
(function() {
var data = %s;
window.opener.postMessage(data, "%s");
window.close();
})();
</script>
</body>
</html>
"""
.formatted(jsonData, targetOrigin);
}

private Map<String, Object> requestOAuthToken(String code, BaseOAuthProperties properties) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ spring:
access-key: ${AWS_ACCESS_KEY_ID}
secret-key: ${AWS_SECRET_ACCESS_KEY}

frontend:
url: ${FRONTEND_URL}

s3:
bucket: ${S3_BUCKET}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ spring:
access-key: ${AWS_ACCESS_KEY_ID}
secret-key: ${AWS_SECRET_ACCESS_KEY}

frontend:
url: ${FRONTEND_URL}

s3:
bucket: ${S3_BUCKET}

Expand Down