javascript - Chrome 中关于跨域读取阻止的警告
问题描述
这是 Spring 和 VueJs 应用程序,我正在学习如何使用 OAuth google(对不起,解释不好),在 application.properites 我正在添加我的 'security.oauth2.client.clientId' 和 'security.oauth2.client.clientSecret'
编译没有问题,也没有例外。我开始 localhost:9000 在我的属性中写入,它的 404 错误并在控制台中显示警告: 跨域读取阻止 (CORB) 阻止了跨域响应 {这里是 google.account 的链接 ... + MIME 类型为 text/html . 有关更多详细信息,请参阅https://www.chromestatus.com/feature/5629709824032768 }
为了检查它是否工作,我打开 localhost:9000/country 并显示我的 json 格式数据,因为它必须是。所以我认为它的问题与我的代码无关,但我不确定。
在我检查了我的 index.html 之后 - 没有“http-equiv="Content-Type" content="text/html;"。我确信它。但是没有......它仍然显示警告。
@Configuration
@EnableWebSecurity
@EnableOAuth2Sso
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/login**", "/js/**", "/error**").permitAll()
.anyRequest().authenticated()
.and().logout().logoutSuccessUrl("/").permitAll()
.and()
.csrf().disable();
}
@Bean
public PrincipalExtractor principalExtractor(UserDetailsRepo userDetailsRepo) {
return map -> {
String id = (String) map.get("sub");
User user = userDetailsRepo.findById(id).orElseGet(() -> {
User newUser = new User();
newUser.setId(id);
newUser.setName((String) map.get("name"));
newUser.setEmail((String) map.get("email"));
newUser.setGender((String) map.get("gender"));
newUser.setLocale((String) map.get("locale"));
newUser.setUserpic((String) map.get("picture"));
return newUser;
});
user.setLastVisit(LocalDateTime.now());
return userDetailsRepo.save(user);
};
}
}
@Controller
@RequestMapping("/")
public class MainController {
@GetMapping
public String main(Model model, @AuthenticationPrincipal User user){
HashMap<Object, Object> data = new HashMap<>();
data.put("profile", user);
data.put("messages", null);
model.addAttribute("frontendData", data);
return "index";
}
@Entity
@Table(name = "usr")
@Data
public class User {
@Id
// @GeneratedValue(strategy = GenerationType.AUTO)
private String id;
private String name;
private String userpic;
private String email;
private String gender;
private String locale;
private LocalDateTime lastVisit;
}
跨域读取阻止 (CORB) 阻止了 MIME 类型为 text/html 的跨域响应https://accounts.google .{etc}。有关详细信息,请参阅https://www.chromestatus.com/feature/5629709824032768 。
解决方案
推荐阅读
- jquery - 单击按钮时如何更改文本?
- java - 如何设置 derby 身份验证和设置用户
- freertos - vTaskStartScheduler() 会覆盖指针参数值,如何避免呢?
- javascript - 如何在 react-admin 中输入 IconPicker 中的图标作为输入?
- database - MySql DB 连接不稳定并且在我们的应用程序中数量不断增加
- r - 如何使用 ggplot 对 R 中的每个分组条重新排序?
- c++ - 在 LLVM 中检测整数比较条件
- python - turtle-graphics:使用 if-else 语句确定海龟参数
- c# - 为什么无法在 Android 中初始化统一引擎?
- cookies - 代码(第三方)iframe 可以设置第一方 cookie 吗?