我正试图在我的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;发布于 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中的问题
https://stackoverflow.com/questions/57886398
复制相似问题