@gameforyouonline

.httpBasic() и как убрать pop-up авторизации?

Доброго времни суток, подскажите пожалуйста, использую spring security:
@Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity)  {

        try {
            return httpSecurity
                    .authorizeRequests()
                    .antMatchers(HttpMethod.GET,"/").permitAll()
                    .antMatchers(HttpMethod.POST, "/categories/select/new", "/products/select/new").authenticated()
                    .antMatchers(HttpMethod.GET, "/categories/**", "/products/**", "/**/**").authenticated()
                    .and()
                    .csrf().disable()
                    .httpBasic()
                    .and()
                    .build();
        } catch (Exception e) {
            log.debug("Error");
            throw new RuntimeException(e);
        }

    }

но, когда на фронте хочу использовать GET получаю pop-up окно для аунтификации и соотвественно не отображаются товари, а вот POST работает. Как мне убрать pop-up окно, но что би соблюдать безопасность.
Методи на фронте:
export const getAllCategories = async () => {

    const response = await fetch(`${URL}${CATEGORIES}`, {
        method: 'GET',
        headers: {
          'Authorization': `Basic ${btoa(credentials)}`
        }
    });
    const data = response.json();
    console.table(data);
    return await response.json();
}

и POST:
const response = await fetch(`${URL}${PRODUCTS}${SELECT}${ADD}`, {
            method: 'POST',
            headers: {
                'Authorization': `Basic ${btoa(credentials)}`
            },
            body: formData,
        })
        if (response.ok) {
            window.location.reload(true);
        } else {
            console.error(`Server responded with ${response.status} ${response.statusText}`);
        }
    }
  • Вопрос задан
  • 53 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы