Spring 使用jHipster oAuth时出现未经授权的错误
我正在运行服务器上启用oAuth身份验证和CORS的jHipster实例。我添加了以下bean:Spring 使用jHipster oAuth时出现未经授权的错误,spring,authentication,oauth,cors,jhipster,Spring,Authentication,Oauth,Cors,Jhipster,我正在运行服务器上启用oAuth身份验证和CORS的jHipster实例。我添加了以下bean: @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = new CorsConfiguration(); config.setAllowCre
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.setAllowedMethods(Arrays.asList(new String[]{"GET", "PUT", "POST", "DELETE", "OPTIONS"}));
source.registerCorsConfiguration("/api/**", config);
source.registerCorsConfiguration("/v2/api-docs", config);
source.registerCorsConfiguration("/oauth/**", config);
return new CorsFilter(source);
}
并将.antMatchers(HttpMethod.OPTIONS,“/oauth/token”).permitAll()添加到ResourceServerConfiguration
当我尝试从浏览器上本地运行的应用程序验证用户(使用服务器上运行的jHipster)时,我得到:
请求方法:选项-状态代码:401未授权
似乎CORS未正确配置以处理飞行前身份验证后请求
我尝试了一些在会议上提出的解决方案,但没有成功
这是不是可以在jHipster中执行的特定操作,以启用从浏览器或应用程序(不在jHipster服务器上运行)工作的身份验证?I未注释的COR行
cors: #By default CORS are not enabled. Uncomment to enable.
allowed-origins: "*"
allowed-methods: GET, PUT, POST, DELETE, OPTIONS
allowed-headers: "*"
exposed-headers:
allow-credentials: true
max-age: 1800
在SecurityConfiguration中添加
**.antMatchers(HttpMethod.OPTIONS, "/**")**
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers(HttpMethod.OPTIONS, "/**")
.antMatchers("/scripts/**/*.{js,html}")
.antMatchers("/bower_components/**")
.antMatchers("/i18n/**")
.antMatchers("/assets/**")
.antMatchers("/swagger-ui/index.html")
.antMatchers("/api/register")
.antMatchers("/api/activate")
.antMatchers("/api/login/**")
.antMatchers("/api/account/reset_password/init")
.antMatchers("/api/account/reset_password/finish")
.antMatchers("/test/**");
}
到目前为止,它一直在工作。您使用的是什么版本的JHipster?如果是最新版本,您只需在application.yml中取消“CORS”部分的注释即可启用CORS。@MattRaible嗨,Matt,感谢您的关注(顺便说一句,我是您的工作和大众汽车的忠实粉丝)。无论如何,我使用的是jHipster 2.23.0。CORS已经启用,但如上所述,飞行前身份验证POST存在一些问题。我自己的服务与CORS配合得很好。我也是我的大众汽车的忠实粉丝!我等不及了您是否尝试过将这些额外的行添加到CsrfCookieGeneratorFilter@jvence嗨,这个运气好吗?我遇到了同样的问题。@I_raqz对不起,运气不好。只是等待jHipster 3.0发布,看看它是否仍然存在