Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
Missing Authorization header Spring Boot CORS

I'm developing an application using Spring Boot on backend and React on frontend. I'm having some issues with CORS and authorization: in particular, when I make a request from the frontend I put the Authorization header which contains the JWT token for authentication. Here an example from the code:

async function getUserInfo (username) {
const url = baseURL + "/users/" + username
const jwt = sessionStorage.getItem('token')

let [err, response] = await to(fetch(url), {
    method: 'GET',
    headers: {
        'Authorization': 'Bearer ' + jwt,
        'Content-Type': 'application/json'
    }
})

...

}

When the request arrives to the backend, this header is missing and authentication fails. To configure CORS on Spring Boot, I use the @CrossOrigin annotation:

@CrossOrigin(origins = ["*"], allowedHeaders = ["*"], exposedHeaders = ["*"])
@RestController
class UserController (
    val userDetailsService: UserDetailsServiceImpl,
    val authenticationManager: AuthenticationManager,
    val jwtUtils: JwtUtils
) {
 
...
 
}

The Security configuration is the following:

override fun configure(http: HttpSecurity) {
    //csrf is enable by default
    http.cors().and().csrf().disable()
        .exceptionHandling().authenticationEntryPoint(authEntryPoint)
        .and()
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .authorizeRequests()
        .antMatchers("/auth/**")
        .permitAll()
        .and()
        .authorizeRequests()
        .antMatchers("/users/{username}/**")
        .hasAuthority("ADMIN")
        .and()
        .authorizeRequests()
        .antMatchers("/**")
        .hasAuthority("CUSTOMER")
        .and()
        .logout()
        .permitAll()

    http.addFilterBefore(JwtAuthenticationTokenFilter(jwtUtils),
        UsernamePasswordAuthenticationFilter::class.java)
}

The requests are made using an ADMIN user on the endpoint /users/{username}, as shown in the frontend code.

How can I solve this problem?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda