DDunDDang
DD's Coding
DDunDDang
전체 방문자
오늘
어제
  • 분류 전체보기 (16)
    • 코드스테이츠_43기 (1)
    • 복습 (11)
      • Java (0)
      • 자료구조, 알고리즘 (1)
      • Spring (2)
      • MYSQL (1)
      • 개발 일지 (6)
      • 배포 (1)
    • 알고리즘 (3)
      • Baekjoon (2)
      • 추가 개념 (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

최근 댓글

최근 글

hELLO · Designed By 정상우.
DDunDDang

DD's Coding

헤더에 Authorization 추가
복습/개발 일지

헤더에 Authorization 추가

2023. 4. 23. 13:57

Postman에서 확인했을 땐 login절차에서 발급된 Authorization을 확인할 수 있었는데,,,프론트 분들께서 확인하셨을 때는 헤더에 담기지 않아 Authorization을 불러올 수 없다고 말씀하셔서 띠용했다...

이렇게 되면 헤더에 달린거 아닌가요 ㅠㅠㅠㅠㅠㅠㅠ

구글링 후 알고보니까 내가 잘못 하고 있었다.....

 

헤더에 포함시킨 줄 알았는데 넣지도 않고 바로 보낸것...

 

 

    @Bean
    public CorsConfigurationSource corsConfigurationSource() {
        CorsConfiguration configuration = new CorsConfiguration();

        configuration.setAllowCredentials(true);
        configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000", "http://localhost:3001"));
        configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PATCH", "DELETE"));
        configuration.setAllowedHeaders(Arrays.asList("*"));
        configuration.addExposedHeader("Authorization");  // 추가된 코드: Authorization 을 헤더에 추가

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);

        return source;
    }

addExposedHeader 부분을 추가해 줬더니 프론트분들께서 Authorization을 확인할 수 있었다.

 

참고로 setAllowCredentials(true) 로 설정하게 되면

configuration.setAlloweOrigins("*"); 패턴을 사용하지 못하게 된다.

-> 경우를 다 적어줘야한다..

'복습 > 개발 일지' 카테고리의 다른 글

크롤링해서 얻은 csv파일을 DB에 입력하기  (0) 2023.04.16
Path parameters with the following names were not found in the request  (0) 2023.04.07
Location Header만 반환하는 메서드에 body 얹기  (0) 2023.04.07
"Unauthorized"  (0) 2023.03.22
하나의 메서드에 두 개의@RequestBody 넣기  (0) 2023.03.05
    '복습/개발 일지' 카테고리의 다른 글
    • 크롤링해서 얻은 csv파일을 DB에 입력하기
    • Path parameters with the following names were not found in the request
    • Location Header만 반환하는 메서드에 body 얹기
    • "Unauthorized"
    DDunDDang
    DDunDDang

    티스토리툴바