-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
217 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/main/java/org/sopt/seonyakServer/global/common/external/googlemeet/GoogleMeetConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package org.sopt.seonyakServer.global.common.external.googlemeet; | ||
|
||
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver; | ||
import com.google.api.gax.core.FixedCredentialsProvider; | ||
import com.google.apps.meet.v2.SpacesServiceSettings; | ||
import com.google.auth.Credentials; | ||
import com.google.auth.oauth2.ClientId; | ||
import com.google.auth.oauth2.DefaultPKCEProvider; | ||
import com.google.auth.oauth2.TokenStore; | ||
import com.google.auth.oauth2.UserAuthorizer; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import org.sopt.seonyakServer.global.exception.enums.ErrorType; | ||
import org.sopt.seonyakServer.global.exception.model.CustomException; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class GoogleMeetConfig { | ||
|
||
@Value("${google.credentials.file.path}") | ||
private String credentialsFilePath; | ||
|
||
@Value("${google.credentials.oauth2.callback.uri}") | ||
private String callbackUri; | ||
|
||
@Value("${google.credentials.tokens.directory.path}") | ||
private String tokensDirectoryPath; | ||
|
||
@Value("${google.credentials.scopes}") | ||
private List<String> scopes; | ||
|
||
private static final String USER = "default"; | ||
|
||
@Bean | ||
public TokenStore tokenStore() { | ||
return new TokenStore() { | ||
private Path pathFor(String id) { | ||
return Paths.get(".", tokensDirectoryPath, id + ".json"); | ||
} | ||
|
||
@Override | ||
public String load(String id) throws IOException { | ||
if (!Files.exists(pathFor(id))) { | ||
return null; | ||
} | ||
return Files.readString(pathFor(id)); | ||
} | ||
|
||
@Override | ||
public void store(String id, String token) throws IOException { | ||
Files.createDirectories(Paths.get(".", tokensDirectoryPath)); | ||
Files.writeString(pathFor(id), token); | ||
} | ||
|
||
@Override | ||
public void delete(String id) throws IOException { | ||
if (!Files.exists(pathFor(id))) { | ||
return; | ||
} | ||
Files.delete(pathFor(id)); | ||
} | ||
}; | ||
} | ||
|
||
@Bean | ||
public UserAuthorizer userAuthorizer(TokenStore tokenStore) throws IOException { | ||
try (InputStream in = getClass().getResourceAsStream(credentialsFilePath)) { | ||
if (in == null) { | ||
throw new CustomException(ErrorType.NOT_FOUND_CREDENTIALS_JSON_ERROR); | ||
} | ||
ClientId clientId = ClientId.fromStream(in); | ||
return UserAuthorizer.newBuilder() | ||
.setClientId(clientId) | ||
.setCallbackUri(URI.create(callbackUri)) | ||
.setScopes(scopes) | ||
.setPKCEProvider(new DefaultPKCEProvider() { | ||
@Override | ||
public String getCodeChallenge() { | ||
return super.getCodeChallenge().split("=")[0]; | ||
} | ||
}) | ||
.setTokenStore(tokenStore) | ||
.build(); | ||
} | ||
} | ||
|
||
@Bean | ||
public LocalServerReceiver localServerReceiver() { | ||
return new LocalServerReceiver.Builder().setPort(8081).build(); | ||
} | ||
|
||
@Bean | ||
public SpacesServiceSettings spacesServiceSettings(Credentials credentials) throws IOException { | ||
return SpacesServiceSettings.newBuilder() | ||
.setCredentialsProvider(FixedCredentialsProvider.create(credentials)) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public Credentials credentials(UserAuthorizer userAuthorizer, LocalServerReceiver localServerReceiver) | ||
throws Exception { | ||
// UserAuthorizer를 사용하여 지정된 사용자의 Credentials를 가져옴 | ||
Credentials credentials = userAuthorizer.getCredentials(USER); | ||
if (credentials != null) { | ||
return credentials; | ||
} else { | ||
throw new CustomException(ErrorType.GET_GOOGLE_AUTHORIZER_ERROR); | ||
|
||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...n/java/org/sopt/seonyakServer/global/common/external/googlemeet/GoogleMeetController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.sopt.seonyakServer.global.common.external.googlemeet; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.sopt.seonyakServer.global.common.external.googlemeet.dto.GoogleMeetUrlResponse; | ||
import org.sopt.seonyakServer.global.exception.enums.ErrorType; | ||
import org.sopt.seonyakServer.global.exception.model.CustomException; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class GoogleMeetController { | ||
private final GoogleMeetService googleMeetService; | ||
|
||
@PostMapping("/google-meet") | ||
public ResponseEntity<GoogleMeetUrlResponse> createSpace() { | ||
try { | ||
return ResponseEntity.ok(googleMeetService.createMeetingSpace()); | ||
} catch (Exception e) { | ||
log.info(e.getMessage()); | ||
throw new CustomException(ErrorType.GET_GOOGLE_MEET_URL_ERROR); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...main/java/org/sopt/seonyakServer/global/common/external/googlemeet/GoogleMeetService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.sopt.seonyakServer.global.common.external.googlemeet; | ||
|
||
import com.google.apps.meet.v2.CreateSpaceRequest; | ||
import com.google.apps.meet.v2.Space; | ||
import com.google.apps.meet.v2.SpacesServiceClient; | ||
import com.google.apps.meet.v2.SpacesServiceSettings; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.seonyakServer.global.common.external.googlemeet.dto.GoogleMeetUrlResponse; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GoogleMeetService { | ||
private final SpacesServiceSettings spacesServiceSettings; | ||
|
||
public GoogleMeetUrlResponse createMeetingSpace() throws Exception { | ||
SpacesServiceClient spacesServiceClient = SpacesServiceClient.create(spacesServiceSettings); | ||
CreateSpaceRequest request = CreateSpaceRequest.newBuilder() | ||
.setSpace(Space.newBuilder().build()) | ||
.build(); | ||
Space response = spacesServiceClient.createSpace(request); | ||
return GoogleMeetUrlResponse.of(response.getMeetingUri()); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...a/org/sopt/seonyakServer/global/common/external/googlemeet/dto/GoogleMeetUrlResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.sopt.seonyakServer.global.common.external.googlemeet.dto; | ||
|
||
public record GoogleMeetUrlResponse( | ||
String googleMeet | ||
) { | ||
public static GoogleMeetUrlResponse of( | ||
final String googleMeet | ||
) { | ||
return new GoogleMeetUrlResponse(googleMeet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...er/global/common/dto/OcrUnivResponse.java → ...n/external/naver/dto/OcrUnivResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters