reactjs - 302 Okta 重定向 - CORS 问题
问题描述
我有一个配置为使用 Okta 作为 SP 发起的 SSO 的 Spring Boot 应用程序,我已将 Okta 开发人员帐户配置为使用“OIDC - OpenID Connect”和“Web 应用程序”作为应用程序类型。
当我从浏览器访问 SP 端点时,访问 Okta 的登录页面没有问题 例如:http://localhost:8080/api/login
但是,当我从我的 React 应用程序调用 API 端点时,它会因 CORS 问题而失败
axios({
method: 'GET',
url: 'http://localhost:8080/api/login',
withCredentials: true
})
.then(response => {
if (response.data.userID)
{
console.log("UserId:" + response.data.userID);
}
})
.catch(error => {
console.error(error);
})
以下是重定向到 Okta(302) 的标头信息似乎是问题所在:
我在 Okta 管理控制台中更新了 react 应用程序的 url 可信来源
以下是 Okta 的登录重定向 uri
这是我的弹簧启动配置:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableOAuth2Sso
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList("*"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
configuration.setAllowedHeaders(Arrays.asList("authorization", "content-type", "x-auth-token"));
configuration.setExposedHeaders(Arrays.asList("x-auth-token"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
@Override
public void configure(WebSecurity webSecurity) throws Exception {
webSecurity
.ignoring()
.antMatchers(HttpMethod.OPTIONS, "/**")
.and()
.ignoring();
}
}
任何想法?我在这里想念什么?
解决方案
推荐阅读
- apache-flink - 在 Flink 延迟指标中获取算子名称
- javascript - 用纯 Javascript 遍历多维数组
- python - Django Rest 框架返回字典而不是 OrderedDicts
- django - Pyinstaller 在 Django 静态 javascript 文件上编译但出现 404 错误
- go - golang 在 1 秒内每 1 毫秒执行一次函数(每秒 1000 次调用)
- rest - SprintBoot 内容类型为空
- angular - 如何以角度在组件之间传递选择器或html标签
- vba - 比较 2 个单元格,然后比较下面的 2 个单元格
- mongodb - 如果根 C 上已经存在数据文件夹怎么办
- google-vr - Google vr 视图使用点击热点更改内容