如何在 Sharepoint Online 中启用 CORS [英] How to enable CORS in Sharepoint Online

查看:67
本文介绍了如何在 Sharepoint Online 中启用 CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 React 应用程序中实现共享点文件浏览器.将 microsoft/file-browser 用于此 ans 代码,如下所示.但是从源 'http://localhost:3000' 获取 xxx... 已被 CORS 策略阻止

I am trying to implement share point file browser in my react application. Using microsoft/file-browser for this ans code as follows. But getting the xxx... from origin 'http://localhost:3000' has been blocked by CORS policy

任何想法如何为此启用 CORS

Any ideas how can I enable CORS for this

import * as React from "react";

import { GraphFileBrowser } from '@microsoft/file-browser';

class App extends React.Component {


  getAuthenticationToken() {
    return new Promise<string>(resolve => {
      resolve(
        "VALID TOKEN"
      );
    });
  }

  render() {
    return (
      <GraphFileBrowser
        getAuthenticationToken={this.getAuthenticationToken}
        onSuccess={(selectedKeys: any[]) => console.log(selectedKeys)}
        onCancel={(err: Error) => console.log(err.message)}
        endpoint='https://XXX.sharepoint.com'

      />
    );
  }
}

export default App;

推荐答案

据我所知,CORS 错误不是因为 SharePoint 而发生,而是因为您的浏览器.这里的问题是您正在尝试将资源从 xxx.sharepoint.com 加载到 localhost(默认情况下,CORS 中永远不会添加该资源)

As far as i can tell the CORS error does not occur because of SharePoint, but because of your Browser. The problem here is that you are trying to load resources from xxx.sharepoint.com to localhost (which per default is never added as accepted in CORS)

因此,一种解决方案是使用对 CORS 不敏感的浏览器.这可能是以下内容:

So one solution would to use a CORS-unsensitive browser. This could be the following:

cd "C:\Program Files (x86)\Google\Chrome\Application"
chrome.exe --disable-web-security --user-data-dir="C:\tmp"

此代码段使用用户数据目录C:\tmp"在没有网络安全"(包括 CORS)的情况下启动您的 Google Chrome.

This snippet starts your Google Chrome without "Web Security" (includes CORS) using the User Data Directory "C:\tmp".

请记住,此解决方法仅适用于开发.在生产中你不应该使用 localhost...

Remember that this workaround only works for development. In production you should not use localhost...

https://www.thepolyglotdeveloper.com/2014/08/bypass-cors-errors-testing-apis-locally/

这篇关于如何在 Sharepoint Online 中启用 CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆