In my project I use OAuth2 authentication for GMail. This is configs:
@Configuration
@Order(97)
@EnableOAuth2Sso
public class OAuth2SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.NEVER)
.and()
.authorizeRequests()
.antMatchers("/gmail/**", "/login")
.authenticated();
}
}
And this is Cors config:
@Configuration
public class CorsConfig {
@Bean
public FilterRegistrationBean corsFilterRegistrationBean() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.applyPermitDefaultValues();
config.setAllowCredentials(true);
config.setAllowedOrigins(Collections.singletonList("*"));
config.setAllowedHeaders(Collections.singletonList("*"));
config.setAllowedMethods(Collections.singletonList("*"));
config.setExposedHeaders(Collections.singletonList("content-length"));
config.setMaxAge(3600L);
source.registerCorsConfiguration("/**", config);
FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
bean.setOrder(0);
return bean;
}
}
I work with VueJS for building UI and of corse I use proxy from VueJS (proxyTable) for all requests.
But I can't authenticate GMail account from UI, when I click on button which send request for authentication, it failed with errors:
This is network:
I don't know what to do else. By the way, from browser authentication, when I endpoint /api/gmail/signin - it works great but from project it's not.