通过 fetch 传递身份验证(Forge API)
我一直在 JS (.NET) 中测试 Forge API,
当我将 Bearer Token 硬编码到 fetch 调用中时,它工作正常,但是当我尝试通过另一个函数传递它时,它会给我错误,
这是我的 fetch
fetch('https://developer.api.autodesk.com/oss/v2/buckets/'+Buk+'/objects?region=EMEA', {
method: 'GET',
headers: {
"Authorization": "Bearer "
}
})
这是我收集令牌的调用
function getForgeToken(callback) {
fetch('/api/forge/oauth/token').then(res => {
res.json().then(data => {
callback(data.access_token, data.expires_in);
});
});
}
正如你所知道的,我是 JS 的新手,任何关于这方面的指导都会很棒。
I've been testing out the Forge API in JS (.NET)
when I hard code the Bearer Token in to the fetch call it works fine, however when I try to pass it through via another function it gives me errors
here is my fetch
fetch('https://developer.api.autodesk.com/oss/v2/buckets/'+Buk+'/objects?region=EMEA', {
method: 'GET',
headers: {
"Authorization": "Bearer "
}
})
here is my call that collects the token
function getForgeToken(callback) {
fetch('/api/forge/oauth/token').then(res => {
res.json().then(data => {
callback(data.access_token, data.expires_in);
});
});
}
As you can tell I'm a novice with JS and any guidance on this would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先我要说的是,不建议直接从浏览器访问 Forge API,因为这基本上会暴露一个访问令牌,该令牌可能具有除“data:read”之外的其他权限。因此,从服务器端代码访问 Forge API 总是更好。
话虽如此,如果您仍然想通过浏览器与 Forge 进行通信,您可以 forge-server -utils。这是我正在维护的 Node.js 的非官方 Forge SDK,它具有在浏览器中使用的实验性支持:https://github.com/petrbroz/forge-server-utils#client-side-experimental。
Let me start by saying that accessing Forge APIs directly from the browser is not recommended as it is basically exposing an access token that could potentially have additional privileges aside from "data:read". For that reason it is always better to access the Forge APIs from your server-side code.
With that said, if you still want to communicate with Forge from the browser, you can the forge-server-utils. This is an unofficial Forge SDK for Node.js that I'm maintaining, and it has an experimental support for use in browsers: https://github.com/petrbroz/forge-server-utils#client-side-experimental.