Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda