首页 > 解决方案 > 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 。

标签: javascriptjavahtmlgoogle-chromebrowser

解决方案


推荐阅读