Когда я запускаю следующую команду Curl для имитации предварительной проверки браузера:
Код: Выделить всё
curl -i -X OPTIONS \
"https://math-morph-backend-qa-scotland-cqdchmerbueeathy.westus-01.azurewebsites.net/vpedtech/auth/login" \
-H "Origin: https://lively-field-0cb114f0f.3.azurestaticapps.net" \
-H "Access-Control-Request-Method: POST"
Код: Выделить всё
HTTP/1.1 403 Forbidden
Date: Mon, 24 Nov 2025 14:54:54 GMT
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: 0
Pragma: no-cache
Transfer-Encoding: chunked
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
X-Frame-Options: DENY
Invalid CORS request
Код: Выделить всё
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable())
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.exceptionHandling(e ->
e.authenticationEntryPoint((req, res, ex) -> res.sendError(HttpServletResponse.SC_UNAUTHORIZED))
.accessDeniedHandler((req, res, ex) -> res.sendError(HttpServletResponse.SC_FORBIDDEN))
);
return http.build();
}
Код: Выделить всё
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();
// 👇 IMPORTANT: your deployed frontend URL must be here
// Use allowedOriginPatterns – more forgiving & modern way
config.setAllowedOriginPatterns(List.of(
"http://localhost:5173",
"https://lively-field-0cb114f0f.3.azurestaticapps.net"
));
config.setAllowedMethods(List.of("GET","POST","PUT","DELETE","OPTIONS","PATCH"));
config.setAllowedHeaders(List.of("*"));
config.setExposedHeaders(List.of("Authorization", "Location"));
config.setAllowCredentials(true);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
System.out.println("🔵 CORS config initialized with allowedOrigins=" + config.getAllowedOrigins());
return source;
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... t-for-post
Мобильная версия