Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, JwtTokenProvid
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**", "/swagger-ui.html").permitAll() // 스웨거 관련 접근 허용
.requestMatchers("/users/oauth/**", "/reissue").permitAll() // 인증 관련 스웨거 접근 허용
.requestMatchers("/home", "/sign-up", "/pots", "/feeds").permitAll()
.requestMatchers("/ws-connect/**").permitAll()
.requestMatchers("/ws-connect/**","/oauth/**").permitAll()
// .requestMatchers("").hasAnyRole("TEMP","ADMIN") // Test를 위해 모든 접근
// .requestMatchers("").hasAnyRole("USER","ADMIN")
// .requestMatchers("").hasRole("ADMIN")// 관리자 권한은 아직 생성하지 않았습니다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.nio.charset.StandardCharsets;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -79,6 +80,12 @@ public class UserController {
private final UserQueryService userQueryService;
private final FeedQueryService feedQueryService;

@Value("${spring.google.client-id}")
private String clientId;

@Value("${spring.google.redirect-uri}")
private String redirectUri;

@GetMapping("/login/token")
@Operation(
summary = "토큰 테스트 API",
Expand Down Expand Up @@ -171,6 +178,28 @@ public ResponseEntity<ApiResponse<UserResponseDto.loginDto>> naverCallback(@Requ
return ResponseEntity.ok(ApiResponse.onSuccess(userResponse));
}

@GetMapping("/start")
public void googleStart(@RequestParam String returnUrl, HttpServletResponse response) throws IOException {

if (!returnUrl.startsWith("http://localhost:5173")) {
throw new IllegalArgumentException("Invalid returnUrl");
}

// state에 returnUrl 넣어서 콜백 때 다시 받기
String state = URLEncoder.encode(returnUrl, StandardCharsets.UTF_8);

String googleAuthUrl =
"https://accounts.google.com/o/oauth2/v2/auth"
+ "?client_id=" + URLEncoder.encode(clientId, StandardCharsets.UTF_8)
+ "&redirect_uri=" + URLEncoder.encode(redirectUri, StandardCharsets.UTF_8)
+ "&response_type=code"
+ "&scope=" + URLEncoder.encode("openid email profile", StandardCharsets.UTF_8)
+ "&access_type=offline"
+ "&prompt=consent"
+ "&state=" + state;

response.sendRedirect(googleAuthUrl);
}
@GetMapping("/oauth/google")
@Operation(
summary = "구글 로그인 및 토큰발급 API",
Expand Down