通过 fetch 传递身份验证(Forge API)

发布于 2025-01-14 02:28:11 字数 594 浏览 3 评论 0原文

我一直在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小忆控 2025-01-21 02:28:11

首先我要说的是,不建议直接从浏览器访问 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文