【发布时间】:2021-05-12 23:07:58
【问题描述】:
我有这个 SpringBoot 应用程序,它通过 Google 使用 OAuth2 登录。而且它本身就可以正常工作。
但是,我正在尝试将它与我的 React 前端连接起来,因此:尝试开发代币交换。
安全配置
http.cors()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/oauth/**")
.authenticated()
.anyRequest()
.permitAll()
.and()
.oauth2Login();
现在,我通过这种方式获取令牌:
OAuth2AuthorizedClient client = authorizedClientService.loadAuthorizedClient(authentication.getAuthorizedClientRegistrationId(), authentication.getName());
String token = client.getAccessToken().getTokenValue();
并将其发送给我的 React 客户端。
问题是:如何在SpringBoot应用中接收和解释授权令牌?
现在,只要我附上 Authoriation 标头,它就会给我一个 CORS 问题...
【问题讨论】:
标签: reactjs spring spring-boot oauth-2.0