【问题标题】:Download of SVF derivatives through forge-apis not authorized未经授权通过forge-apis下载SVF衍生品
【发布时间】:2018-01-18 19:35:26
【问题描述】:

在最近使用 extract.autodesk.io 模块 (SVF model derivative downloaded as an (almost) empty ZIP file (Autodesk Forge)) 解决的帖子之后,我仍然无法仅使用官方 forge 下载 SVF 模型衍生品-apis 模块,在 2 足环境中。

这是我试图实现的最小示例:

var ForgeSDK = require("forge-apis");

/* The next four lines are filled with my credentials and URN values 
 * (this shouldn't be the problem, since getting the manifest for the URN
 * is performed successfully) */
var client_id = "...";
var client_secret = "...";
var urn = "...";
var derivative_urn = "...";

var derivatives = new ForgeSDK.DerivativesApi();
var autoRefresh = true;
var oAuth2TwoLegged = new ForgeSDK.AuthClientTwoLegged(client_id, 
    client_secret, [
        "data:read", "data:write", "bucket:read", "bucket:write"
    ], autoRefresh);

oAuth2TwoLegged.authenticate().then(function(credentials) {
    derivatives.getDerivativeManifest(urn, derivative_urn, {}, credentials, oAuth2TwoLegged).then(function(content) {
        console.log(content);
    }).catch(function(err) {
        if (err) {
            console.log(err);
        }
    })
});

我收到以下错误:{ statusCode: 401, statusMessage: 'Unauthorized' }。是范围问题吗?

提前非常感谢!

PS:我知道 extract.autodesk.io 提供了一个很好的方法来做到这一点,但我觉得使用 bubble 对象并不是那么简单的转置另一个上下文。 forge-apis 模块应该可以无缝地完成这项工作(或者我遗漏了一些东西)。

更新:按照 Augusto 的建议,我使用了最基本的命令(即 cUrl)从 IFC 文件中下载信息。下面的前两个命令成功运行(下载清单和 PNG 屏幕截图文件)。 SVF 的下载似乎也可以正常工作,只是 ZIP 文件只包含两个 JSON 文件(manifest.json 和 metadata.json),以及三个空目录(几何、材质、场景)。

代码如下:

# Get manifest for the IFC file
curl -X "GET" -H "Authorization: Bearer $TOKEN" -v "https://developer.api.autodesk.com/modelderivative/v2/designdata/$URN_IFC/manifest" > manifest.json

# Get a PNG related to the IFC file
curl -X "GET" -H "Authorization: Bearer $TOKEN" -v "https://developer.api.autodesk.com/modelderivative/v2/designdata/$URN_IFC/manifest/$URN_PNG" > image.png

# Get the SVF converted from the IFC file
curl -X "GET" -H "Authorization: Bearer $TOKEN" -v "https://developer.api.autodesk.com/modelderivative/v2/designdata/$URN_IFC/manifest/$URN_SVF" > output.zip

有什么想法吗?

【问题讨论】:

  • 这似乎是一个您看不到的 URN/Bucket,您可以使用 Postman(或类似工具)在该端点上尝试一个简单的 GET 吗?
  • 感谢奥古斯托的建议。我已经在编辑中回答了(见更新)。
  • 谢谢@Rajan,我会检查代码,但你能确认一下包版本 0.4.1 吗?我知道我们最近做了一些修复。 npmjs.com/package/forge-apis
  • 是的,我用的是0.4.1版本的forge-apis。感谢您的帮助。

标签: node.js autodesk-forge autodesk-model-derivative


【解决方案1】:

查看the implementationnpm forge-apis@0.4.1,签名为:

this.getDerivativeManifest = function(urn, derivativeUrn, opts, oauth2client, credentials)

但您的代码似乎以相反的顺序使用oauth2clientcredentials。更改后,它在这里工作正常。

var derivatives = new ForgeSDK.DerivativesApi();
var autoRefresh = true;
var oAuth2TwoLegged = new ForgeSDK.AuthClientTwoLegged(client_id, 
    client_secret, [
        "viewables:read"
    ], autoRefresh);

oAuth2TwoLegged.authenticate().then(function(credentials) {
    derivatives.getDerivativeManifest(urn, derivative_urn, {}, oAuth2TwoLegged, credentials).then(function(content) {
        console.log(content);
    }).catch(function(err) {
        if (err) {
            console.log(err);
        }
    })
});

建议仅使用 viewables:read 范围,因为您不需要所有这些额外权限(至少对于此代码)。

【讨论】:

  • 这很奇怪......我已经检查了两个订单(凭据和 oauth2client),而您建议的订单导致“{ statusCode:400,statusMessage:'Bad Request'}”,而我的导致“{ statusCode:401,statusMessage:'Unauthorized'}”。无论如何,我还检查了令牌的简单生成,我得到“...\node_modules\forge-apis\src\auth\OAuth2.js:42 throw specificScope[key] + " scope is not allowed"; viewables:read scope is not allowed" => 这是与 Forge 相关的范围问题帐号?
  • 如果我对派生的 URN 进行 base64 编码,那么我得到BadRequest,检查一下。 viewables:read scope is not allowed 可能意味着您拥有旧版本的 SDK,建议您使用新的 npm install forge-apis@0.4.1 --save
  • 从您的原始代码中,bucket:write 是不允许的,这表明您可能拥有旧版本的 SDK(因为它为您工作),请参阅 github.com/Autodesk-Forge/forge-api-nodejs-client/blob/master/…developer.autodesk.com/en/docs/oauth/v2/overview/scopes
  • 嗯...我重新安装了 forge-apis,现在可以使用您编写的代码(仍然很奇怪,因为我之前的安装已经在 package.json 中提到了 v0.4.1 ,但无论如何...)。问题是我们回到了我最初的帖子,即下载现在就像使用 cUrl 命令一样:没有错误(statusCode=200),下载了一个 zip 文件,但其中包含空目录(如更新中所述更多)。会不会和我写缓冲区的方式有关?
  • 我这样写缓冲区:derivatives.getDerivativeManifest(urn, derivative_urn, {}, oAuth2TwoLegged, credentials).then(function(content) { var stream = fs.createWriteStream("svf.zip"); stream.write(content.body); stream.end(); }。提前致谢。
【解决方案2】:

在将 forge-apis NPM 包更新到最新版本 (0.4.1) 后,我对 extract.autodesk.iobubble.js 函数进行了新尝试,现在它工作正常: 我可以毫不费力地下载 SVF 文件。

感谢@Augusto 的帮助。仍然很想知道为什么“基本” cUrl 方法不能按预期工作......

【讨论】:

    猜你喜欢
    • 2017-12-06
    • 2017-08-07
    • 2018-11-07
    • 1970-01-01
    • 2018-06-15
    • 2016-02-17
    • 1970-01-01
    • 2020-05-03
    • 2018-01-17
    相关资源
    最近更新 更多