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

[#72] Fix: redirect uri for login #86

Merged
merged 19 commits into from
May 19, 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
39 changes: 37 additions & 2 deletions src/main/java/com/syncd/adapter/in/web/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
import com.syncd.application.service.LoginService;
import com.syncd.dto.TokenDto;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;

import java.util.Collection;
import java.util.Enumeration;

@RestController
@RequiredArgsConstructor
@RequestMapping("/login/oauth2")
Expand All @@ -20,10 +25,40 @@ public class AuthController {
private final AuthControllerProperties authControllerProperties;

@GetMapping("/code/{registrationId}")
public RedirectView googleLogin(@RequestParam String code, @PathVariable String registrationId, HttpServletResponse response) {
public RedirectView googleLogin(@RequestParam String code,
@PathVariable String registrationId,
HttpServletRequest request,
HttpServletResponse response) {
String url = authControllerProperties.getRedirectUrl();
TokenDto token = socialLoginUsecase.socialLogin(code, registrationId);
String redirectUrl = url + token.accessToken();

Enumeration<String> reqHeaderNames = request.getHeaderNames();

while (reqHeaderNames.hasMoreElements()) {
String headerName = reqHeaderNames.nextElement();
String headerValue = request.getHeader(headerName);
System.out.println(headerName + ": " + headerValue);
}
String cookies = request.getHeader("cookie");
String refererSubstring="";
int refererIndex = cookies.indexOf("referer=");
if (refererIndex != -1) {
// 'referer=' 이후의 부분 추출
refererSubstring = cookies.substring(refererIndex + "referer=".length());

// ';' 이전의 부분 추출 (쿠키가 끝날 때까지)
int semicolonIndex = refererSubstring.indexOf(';');
if (semicolonIndex != -1) {
refererSubstring = refererSubstring.substring(0, semicolonIndex);
}

System.out.println("Referer: " + refererSubstring);
} else {
System.out.println("Referer not found.");
refererSubstring = "https://syncd.i-dear.org/";
}

String redirectUrl = refererSubstring + url + token.accessToken();
return new RedirectView(redirectUrl);
}
}
8 changes: 2 additions & 6 deletions src/main/java/com/syncd/adapter/in/web/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ public class LoginController {
@GetMapping("/login/google")
public RedirectView redirectToGoogleOAuth(HttpServletRequest request) {
String redirectUrl = googleOAuth2Properties.getRedirectUri();
String targetUrl = request.getHeader("Referer")+"login/oauth2/code/google";
if (targetUrl == null || targetUrl.isBlank()) {
// 기본 URL 설정
targetUrl = redirectUrl;
}
System.out.println(targetUrl);
String targetUrl = redirectUrl;
String url = "https://accounts.google.com/o/oauth2/auth" +
"?client_id=70988875044-9nmbvd2suleub4ja095mrh83qbi7140j.apps.googleusercontent.com" +
"&redirect_uri=" + targetUrl +
"&response_type=code" +
"&scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile";
System.out.println(url);
return new RedirectView(url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public MakeUserStoryResponseDto makeUserstory(List<String> scenario) {
try {
MakeUserStoryResponseDto responseDto = promptUserStory(finalToken, om, scenario);
System.out.println(finalToken);
for (MakeUserStoryResponseDto.EpicDto epic : responseDto.getEpics()) {
// 각 Epic의 UserStories를 순회합니다.
for (MakeUserStoryResponseDto.UserStoryDto userStory : epic.getUserStories()) {
// 각 UserStory의 id에 epic.id * 100을 더합니다.
userStory.setId(userStory.getId() + Integer.parseInt(epic.getId()) * 100);
}
}
return responseDto;
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public TokenDto socialLogin(String code, String registrationId) {

private String getAccessToken(String authorizationCode, String registrationId) {


MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("code", authorizationCode);
params.add("client_id", clientId);
Expand Down
Loading