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 @@ -11,22 +11,35 @@

import gg.agit.konect.global.auth.annotation.PublicApi;
import gg.agit.konect.global.auth.annotation.UserId;
import gg.agit.konect.infrastructure.oauth.dto.GoogleDriveAuthorizationUrlResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/auth/oauth/google/drive")
@Tag(name = "(Normal) OAuth - Google Drive")
public class GoogleDriveOAuthController {

private final GoogleDriveOAuthService googleDriveOAuthService;

@Operation(summary = "Google Drive 권한 연결 URL 조회")
@GetMapping("/authorize-url")
public ResponseEntity<GoogleDriveAuthorizationUrlResponse> getAuthorizationUrl(@UserId Integer userId) {
String authUrl = googleDriveOAuthService.buildAuthorizationUrl(userId);
return ResponseEntity.ok(new GoogleDriveAuthorizationUrlResponse(authUrl));
}

@Operation(summary = "Google Drive 권한 연결 페이지로 리다이렉트")
@GetMapping("/authorize")
public ResponseEntity<Void> authorize(@UserId Integer userId) {
String authUrl = googleDriveOAuthService.buildAuthorizationUrl(userId);
return ResponseEntity.status(HttpStatus.FOUND).location(URI.create(authUrl)).build();
}

@PublicApi
@Operation(summary = "Google Drive OAuth callback 처리")
@GetMapping("/callback")
public ResponseEntity<Void> callback(
@RequestParam("code") String code,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gg.agit.konect.infrastructure.oauth.dto;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

import io.swagger.v3.oas.annotations.media.Schema;

public record GoogleDriveAuthorizationUrlResponse(
@Schema(
description = "Google Drive 권한 연결을 위해 브라우저를 이동시킬 authorize URL",
example = "https://accounts.google.com/o/oauth2/v2/auth?client_id=example&redirect_uri=https://api.stage.agit.gg/auth/oauth/google/drive/callback&response_type=code&scope=https://www.googleapis.com/auth/drive&access_type=offline&prompt=consent&state=example-state",
requiredMode = REQUIRED
)
String authorizationUrl
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package gg.agit.konect.integration.infrastructure.oauth;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

import gg.agit.konect.infrastructure.oauth.GoogleDriveOAuthService;
import gg.agit.konect.support.IntegrationTestSupport;

class GoogleDriveOAuthControllerTest extends IntegrationTestSupport {

@MockitoBean
private GoogleDriveOAuthService googleDriveOAuthService;

private static final Integer USER_ID = 100;
private static final String AUTHORIZATION_URL =
"https://accounts.google.com/o/oauth2/v2/auth?client_id=test-client&state=test-state";

@BeforeEach
void setUp() throws Exception {
mockLoginUser(USER_ID);
}

@Nested
@DisplayName("GET /auth/oauth/google/drive/authorize-url - Google Drive 권한 연결 URL 조회")
class GetAuthorizationUrl {

@Test
@DisplayName("로그인 사용자의 authorize URL을 JSON으로 반환한다")
void getAuthorizationUrl() throws Exception {
given(googleDriveOAuthService.buildAuthorizationUrl(eq(USER_ID)))
.willReturn(AUTHORIZATION_URL);

performGet("/auth/oauth/google/drive/authorize-url")
.andExpect(status().isOk())
.andExpect(jsonPath("$.authorizationUrl").value(AUTHORIZATION_URL));
}
}
}
Loading