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
7 changes: 6 additions & 1 deletion MR_config/local/application.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ jwt:
access-token-validity-in-seconds: 1800 # Access Token 만료 시간 (30분)
refresh-token-validity-in-seconds: 604800 # Refresh Token 만료 시간 (7일)

# CORS 설정
cors:
allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:5173,https://www.musereview.site}

# 소셜 로그인 API 연동
oauth:
frontend-redirect-uri: ${OAUTH_FRONTEND_REDIRECT_URI:https://www.musereview.site/oauth/callback}
frontend-redirect-uris:
- http://localhost:5173/oauth/callback
- https://musereview-sigma.vercel.app/oauth/callback
- https://www.musereview.site/oauth/callback
temp-code-ttl: ${OAUTH_TEMP_CODE_TTL:2m}
cookie:
secure: ${OAUTH_COOKIE_SECURE:false}
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/com/mr/domain/auth/service/OAuthClientService.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,35 +318,38 @@ public String getAuthorizationUrl(SocialType socialType, String customRedirectUr
return builder.build().toUriString();
}

private String resolveFrontendRedirectBaseUrl(String customFrontendRedirectUri) {
if (customFrontendRedirectUri != null && isFrontendAllowedRedirectUri(customFrontendRedirectUri)) {
return customFrontendRedirectUri.trim();
}
if (oAuthProperties != null && oAuthProperties.frontendRedirectUri() != null && !oAuthProperties.frontendRedirectUri().isBlank()) {
return oAuthProperties.frontendRedirectUri().trim();
}
if (oAuthProperties != null && !oAuthProperties.getAllowedFrontendRedirectUris().isEmpty()) {
return oAuthProperties.getAllowedFrontendRedirectUris().get(0);
}
return "http://localhost:5173/oauth/callback";
}

public String buildFrontendRedirectUrl(String code) {
return buildFrontendRedirectUrl(code, (String) null);
}

public String buildFrontendRedirectUrl(String code, String customFrontendRedirectUri) {
String baseUrl = (customFrontendRedirectUri != null && isFrontendAllowedRedirectUri(customFrontendRedirectUri))
? customFrontendRedirectUri.trim()
: (oAuthProperties != null && oAuthProperties.frontendRedirectUri() != null && !oAuthProperties.frontendRedirectUri().isBlank())
? oAuthProperties.frontendRedirectUri()
: "http://localhost:5173/oauth/callback";
String baseUrl = resolveFrontendRedirectBaseUrl(customFrontendRedirectUri);

return org.springframework.web.util.UriComponentsBuilder.fromUriString(baseUrl)
.queryParam("code", code)
.build()
.toUriString();
}



public String buildFrontendErrorRedirectUrl(String error) {
return buildFrontendErrorRedirectUrl(error, (String) null);
}

public String buildFrontendErrorRedirectUrl(String error, String customFrontendRedirectUri) {
String baseUrl = (customFrontendRedirectUri != null && isFrontendAllowedRedirectUri(customFrontendRedirectUri))
? customFrontendRedirectUri.trim()
: (oAuthProperties != null && oAuthProperties.frontendRedirectUri() != null && !oAuthProperties.frontendRedirectUri().isBlank())
? oAuthProperties.frontendRedirectUri()
: "http://localhost:5173/oauth/callback";
String baseUrl = resolveFrontendRedirectBaseUrl(customFrontendRedirectUri);

return org.springframework.web.util.UriComponentsBuilder.fromUriString(baseUrl)
.queryParam("error", (error != null && !error.isBlank()) ? error : "authentication_failed")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mr/global/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
return http.build();
}

@org.springframework.beans.factory.annotation.Value("${cors.allowed-origins:http://localhost:3000,http://localhost:5173,https://musereview-sigma.vercel.app}")
@org.springframework.beans.factory.annotation.Value("${cors.allowed-origins:http://localhost:5173,https://www.musereview.site}")
private String allowedOrigins;

// CORS 설정
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ jwt:
access-token-validity-in-seconds: 1800 # Access Token 만료 시간 (30분)
refresh-token-validity-in-seconds: 604800 # Refresh Token 만료 시간 (7일)

# CORS 설정
cors:
allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:5173,https://www.musereview.site}

# 소셜 로그인 API 연동
oauth:
frontend-redirect-uri: ${OAUTH_FRONTEND_REDIRECT_URI:https://www.musereview.site/oauth/callback}
frontend-redirect-uris:
- http://localhost:5173/oauth/callback
- https://musereview-sigma.vercel.app/oauth/callback
- https://www.musereview.site/oauth/callback

temp-code-ttl: ${OAUTH_TEMP_CODE_TTL:2m}
cookie:
Expand Down
Loading