0

I have this SpringBoot app, which uses the OAuth2 login via Google. And it works just fine on it's own.

However, I'm trying to connect it with my React frontend and thus: trying to develop the exchange of tokens.

SecurityConfig

http.cors()
      .and()
      .authorizeRequests()
      .antMatchers(HttpMethod.GET, "/oauth/**")
      .authenticated()
      .anyRequest()
      .permitAll()
      .and()
      .oauth2Login();

Now, I'm obtaining the token this way:

OAuth2AuthorizedClient client = authorizedClientService.loadAuthorizedClient(authentication.getAuthorizedClientRegistrationId(), authentication.getName());
String token = client.getAccessToken().getTokenValue();

and send it to my React client.

The question is: how to receive and interpret the authorization token at SpringBoot app? Right now it's giving me a CORS issue as soon as I attach the Authoriation header...

k-wasilewski
  • 3,943
  • 4
  • 12
  • 29

1 Answers1

0

you have to configure the allowed CORS requests in your spring boot app or serve your react frontend from the same domain.

personally ive always done the second option, with the spring boot app serving the react bundle on some url (e.g. /static/js/).

murphy1312
  • 553
  • 9
  • 18