无法检索访问令牌

时间:2021-01-21 16:03:01

标签: authentication autodesk-forge autodesk autodesk-model-derivative

我正在使用 gitlab 代码试验这个 https://forge-digital-twin.autodesk.io/#。我可以在本地显示它(没有引擎或数据流),但我无法获得访问令牌。

我正在使用 VSCode 扩展,如果我尝试创建存储桶等,我会收到代码 401(未经授权)错误(因此我尝试获取访问代码)。但是,当我使用它请求一个时:

curl -i -X POST 'https://developer.api.autodesk.com/authentication/v1/authenticate' -H 'Content-Type: application/x-www-form-urlencoded' -d 'client_id= -----' -d 'client_secret= ----' -d 'grant_type=client_credentials' -d 'scope=data:write data:read bucket:create bucket:delete'

我收到此错误:

Invoke-WebRequest:无法绑定参数“Headers”。无法转换“内容类型: application/x-www-form-urlencoded” 类型为“System.String”的值输入 “System.Collections.IDictionary”。 在行:1 字符:90

  • ... ticate' -H 'Content-Type: application/x-www-form-urlencoded' -d 'cl ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    • FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRe
      任务命令

我不知道我哪里出错了,我已经尝试了所有我能想到的方法。

希望能帮到你,谢谢:)

2 个答案:

答案 0 :(得分:0)

默认为 Invoke-WebRequest。 尝试像这样使用 Invoke-RestMethod:

$Body = @{
    grant_type = "client_credentials"
    client_id = ""
    client_secret = ""
    scope = "data:write data:read bucket:create bucket:delete"
}
$Headers = @{
    'Content-Type' = 'application/x-www-form-urlencoded'
}

$response = Invoke-RestMethod -Method Post -Uri https://developer.api.autodesk.com/authentication/v1/authenticate' -Headers $Headers -Body $Body

答案 1 :(得分:0)

如果您在使用 Visual Studio Code 的 Forge 扩展时看到 401 问题,请确保您至少有一个“环境”配置了您的 Forge 客户端 ID 和密码。当您第一次激活扩展时,它应该会自动要求您提供凭据,但您也可以随时通过转到 Visual Studio Code 首选项并查找“forge”来添加或编辑环境:

Find Forge Settings

然后,在 Autodesk > Forge: Environments 部分,点击 Edit in settings.json 链接并直接将环境编辑为 JSON,创建一个新对象(如果需要,设置 titleclientIdclientSecret 属性):

Edit Forge Environments

<块引用>

顺便说一句。 VSCode 在编辑 settings.json 文件时提供智能感知支持,因此您将准确了解每个环境中预期/可用的属性。