我正试图在我的react应用程序中实现共享点文件浏览器。对此ans代码使用microsoft/file-browser如下所示。但是得到了xxx... from origin 'http://localhost:3000' has been blocked by CORS policy
有什么想法吗?我怎样才能让CORS做到这一点?
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;发布于 2019-09-16 10:51:13
据我所知,CORS错误并不是因为SharePoint而发生的,而是因为您的浏览器。这里的问题是,您正在尝试将资源从xxx.sharepoint.com加载到本地主机(默认情况下,在CORS中从未将其添加为可接受的)。
因此,一种解决方案是使用CORS--不敏感的浏览器。这可以是:
cd "C:\Program Files (x86)\Google\Chrome\Application"
chrome.exe --disable-web-security --user-data-dir="C:\tmp"这段代码段使用用户数据目录"C:\tmp“启动您的Google,而没有使用"Web”(包括CORS)。
请记住,这种解决方法只适用于开发。在生产中你不应该使用本地主机..。
https://www.thepolyglotdeveloper.com/2014/08/bypass-cors-errors-testing-apis-locally/
发布于 2021-01-28 01:29:33
您正在访问的web应用程序支持CORS (或不支持)。早期版本的SharePoint很少或根本不支持CORS。
SharePoint 2016及以上版本要求您在所有CORS呼叫中使用OAuth。这可以通过低/高信任的外接程序令牌或AAD应用程序令牌来完成。任何由OAuth识别的有效SharePoint令牌都可以工作。这是一个广泛的主题,但您可以在这里阅读外接程序身份验证- SharePoint外接程序的授权与认证。
在SharePoint的早期版本(2013年及之前)中,您可以使用IIS中的URL重写规则或响应头来伪造SharePoint中缺乏的CORS支持。既然它支持它,就不能伪造它,它需要身份验证。
这里有更多信息- 修正跨域ajax调用SharePoint rest中的问题
发布于 2019-09-22 12:20:53
默认情况下(在JavaScript API中),跨源资源共享在现代浏览器中被阻止。
为了处理来自不同领域的web应用程序中的跨域Ajax请求,生产服务器必须是CORS-启用。但是,如果您只需要为开发绕过它,就可以使用允许CORS:访问-控制-允许-起源铬扩展来启用/禁用CORS检查。
https://stackoverflow.com/questions/57886398
复制相似问题