🌳 에러 코드
응답 헤더 (Authorization’, ‘Authorization-refresh) 토큰 관련 헤더가 들어오지 않는 문제.
🌳 해결 방법
🌾 해결 방법 : 응답 헤더 설정은 setExposedHeaders 메소드로 해결!
Before
Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.cors() // cors 설정
.and()
...
return http.build();
}
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList("<http://localhost:8080>", "..."));
configuration.setAllowedMethods(Arrays.asList("HEAD", "GET", "POST", "PATCH", "DELETE", "OPTIONS"));
configuration.setAllowCredentials(true);
configuration.setAllowedHeaders(Arrays.asList("Authorization", "Authorization-refresh", "Cache-Control", "Content-Type"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
After
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.cors() // cors 설정
.and()
...
return http.build();
}
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList("<http://localhost:8080>", "..."));
configuration.setAllowedMethods(Arrays.asList("HEAD", "GET", "POST", "PATCH", "DELETE", "OPTIONS"));
configuration.setAllowCredentials(true);
configuration.setAllowedHeaders(Arrays.asList("Authorization", "Authorization-refresh", "Cache-Control", "Content-Type"));
/* 응답 헤더 설정 추가*/
configuration.setExposedHeaders(Arrays.asList("Authorization", "Authorization-refresh"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
'코딩 에러 및 질문' 카테고리의 다른 글
javax.persistence.NonUniqueResultException (0) | 2023.10.22 |
---|---|
발생한 예외의 종류에 상관없이 403 Forbidden 응답이 반환 With Spring Security (0) | 2023.09.17 |
월별 성별에 따른 조회 JPA - nativeQuery (0) | 2023.09.08 |
Mysql - (년도 + 월) 합쳐서 조회하기 (0) | 2023.09.07 |
"could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet", (0) | 2023.09.07 |