Reactjs 服务器发送facebook社交登录重定向URL的CORS错误
因此,我使用Spring(java)编写了一个RESTAPI,它使用基本身份验证进行保护,并负责处理社交登录。下面是facebook登录的配置Reactjs 服务器发送facebook社交登录重定向URL的CORS错误,reactjs,spring-security,spring-security-oauth2,spring-data-rest,spring-social-facebook,Reactjs,Spring Security,Spring Security Oauth2,Spring Data Rest,Spring Social Facebook,因此,我使用Spring(java)编写了一个RESTAPI,它使用基本身份验证进行保护,并负责处理社交登录。下面是facebook登录的配置 @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { //autowired @Bean @Override protected AuthenticationManager
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
//autowired
@Bean
@Override
protected AuthenticationManager authenticationManager() throws Exception {
return super.authenticationManager();
}
@Bean
public ProviderSignInController providerSignInController() {
return new ProviderSignInController(connectionFactoryLocator(), usersConnectionRepository(),
new FacebookSignInAdapter());
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(NoOpPasswordEncoder.getInstance());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login*", "/signin/**", "/signup/**").permitAll()
.anyRequest().authenticated()
.and().httpBasic()
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().csrf().disable()
;
}
@Bean
public ConnectionFactoryLocator connectionFactoryLocator() {
ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
registry.addConnectionFactory(new FacebookConnectionFactory(environment.getProperty("facebook.clientId"),
environment.getProperty("facebook.clientSecret")));
return registry;
}
@Bean
public UsersConnectionRepository usersConnectionRepository() {
return new InMemoryUsersConnectionRepository(connectionFactoryLocator());
}
}
使用的依赖项:
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-facebook</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
那么,这个问题的解决方案是什么?我在谷歌上搜索了一下,发现CORS是由后端处理的,而不是前端。但是后端已经在处理COR了。此配置应该是什么?您使用什么浏览器?你试过不同的浏览器吗?看起来您正在从本地文件系统加载前端。你…吗?你试着从服务器加载前端了吗?@dur Chrome。是的,我也尝试过狩猎旅行。是的,应用程序处于开发模式,我只使用注册功能,因此没有尝试从服务器加载前端。“一切都是本地的。@编码员:您能找到解决方法吗?”?在进行本地测试时,使用LinkedIn进行社交登录,我也面临着类似的问题。
Access to XMLHttpRequest at 'https://www.facebook.com/v2.5/dialog/oauth?client_id=2198xxxxxx91&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8443%2Fsignin%2Ffacebook&state=xxxx' (redirected from 'https://localhost:8443/signin/facebook') from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.