Autodesk Forge C# 问题创建 API 错误,AUTH-010

Autodesk Forge C# Issue Creation API Error, AUTH-010

我正在测试问题创建代码(来源:forge-checkmodels-createissues-revit/web/Controllers/BIM360.cs)。 我在下面收到一条错误消息。

我的问题是两个

  1. 什么是 errorCode: AUTH-010 developers_guide error_handling 中没有解释。 我检查了 BIM 360 Project Admin Services 的问题菜单上的设置 "Permission Level was set to Full Control",我猜不出可疑 "Token does not have the privilege for this request".

  2. 你能推荐一下Github的示例代码吗?或者建议我进行额外的代码检查。

提前致谢。

{"Request":{"UserState":null,"AllowedDecompressionMethods":[0,2,1],"AlwaysMultipartFormData":false,"JsonSerializer":{ "DateFormat":null,"RootElement":null,"Namespace":null,"ContentType":"application/json"},"XmlSerializer":{"RootElement":空,"Namespace":空,"DateFormat":空,"ContentType":"text/xml"},"ResponseWriter":空,"UseDefaultCredentials":假,"Parameters":[{"Name":"Authorization","Value":"Bearer eyJhbGciOiJIUzI1NiIsImtpZCI6Imp3dF9zeW1tZXRyaWNfa2V5In0.eyJ1c2VyaWQiOiJVMzlKSldYTlhGOUoiLCJleHAiOjE1ODM5MTc2ODYsInNjb3BlIjpbImRhdGE6cmVhZCJdLCJjbGllbnRfaWQiOiJidmlheEd0R3BFd1pGcWw1dkpsb2k4SUF4a1E0Ym9YRSIsImdyYW50X2lkIjoia0h3R1FWRXZXU3g4MUlvOVFuWU5UdkdjRU94NjBFaWkiLCJhdWQiOiJodHRwczovL2F1dG9kZXNrLmNvbS9hdWQvand0ZXhwNjAiLCJqdGkiOiJFTnFEcmZwaUo0eFdKQm9lNm1DZUV1RFVlZ2VuT2FIUnlPRUpNR3h1UExjakwzYW1nTjRBQ2RTOEdST3Q3NTlLIn0.1VYYXE2ZXcV6Qr2PiGJqMIZNY-Rr2D3EngBVYEcqiXc","Type":3,"ContentType":null},{"Name":"Content-Type","Value":"application/vnd.api+json","Type":3,"ContentType":null},{"Name":"container_id" ,"Value":"45b8e606-f4e3-4233-a508-cbfb0098d28a","Type":2,"ContentType":null},{"Name":"text/json","Value":"{\"data\":{\"type\":\"issues\",\"attributes\":{\"title\":\"이슈생성 API 테스트-1\",\"description\":\"이슈생성 API 테스트-1(나는 내용입니다.)\",\"status\":\"open\" ,\"starting_version\":\"1\",\"target_urn\":\"1\",\"due_date\":\"2020-03-12T01:19:54.861Z\",\ "assigned_to\":\"U39JJWXNXF9J\",\"owner\":\"U39JJWXNXF9J\"}}}","Type":4,"ContentType":null},{"Name":"Accept","Value":"application/json, application/xml, text/json, text/x-json, text/javascript, text/xml","Type":3,"ContentType":null}],"Files":[], "Method":1,"Resource":"/issues/v1/containers/{container_id}/质量问题","RequestFormat":1,"RootElement":null, "OnBeforeDeserialization":{"Method":{"Name":"<.ctor>b__1_0","AssemblyName":"RestSharp, Version=106.3.1.0, Culture=neutral, PublicKeyToken=598062e77f915f75","ClassName": "RestSharp.RestRequest+<>c","Signature":"Void <.ctor>b__1_0(RestSharp.IRestResponse)","Signature2":"System.Void <.ctor>b__1_0(RestSharp.IRestResponse)","MemberType":8,"GenericArguments":null},"Target":{}},"DateFormat":null,"XmlNamespace":null,"Credentials":null,"Timeout":0,"ReadWriteTimeout":0 ,"Attempts":0},"ContentType":"application/json","ContentLength":192,"ContentEncoding":"","Content":"{ \"developerMessage\":\"

Token does not have the privilege for this request.

\", \"moreInfo\": \"https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/\", \

"errorCode\": \"AUTH-010\"

}","StatusCode":403,"IsSuccessful":false,"StatusDescription":"Forbidden","RawBytes":"eyAiZGV2ZWxvcGVyTWVzc2FnZSI6IlRva2VuIGRvZXMgbm90IGhhdmUgdGhlIHByaXZpbGVnZSBmb3IgdGhpcyByZXF1ZXN0LiIsICJtb3JlSW5mbyI6ICJodHRwczovL2ZvcmdlLmF1dG9kZXNrLmNvbS9lbi9kb2NzL29hdXRoL3YyL2RldmVsb3BlcnNfZ3VpZGUvZXJyb3JfaGFuZGxpbmcvIiwgImVycm9yQ29kZSI6ICJBVVRILTAxMCJ9","ResponseUri":"https://developer.api.autodesk.com/issues/v1/containers/45b8e606-f4e3-4233-a508-cbfb0098d28a/quality-issues","Server":"","Cookies":[],"Headers":[{"Name":"Access-Control-Allow-Credentials", "Value":"true","Type":3,"ContentType":null},{"Name":"Access-Control-Allow-Headers","Value":"Content-Length,x-ads-ul-ctx-client-id,x-ads-ul-ctx-caller-span-id,Content-Range,Access-Control-Allow-Origin,Authorization,x-ads-test,x-ads-ul-ctx-oxygen-id,x-ads-acm-scopes,x-ads-ul-ctx-head-span-id,If-Match,x-ads-ul-ctx-source,Accept-Encoding,If-Modified-Since,x-ads-acm-namespace,Access-Control-Allow-Credentials,x-ads-acm-groups,Session-Id,Content-Encoding,x-ads-ul-ctx-scope,Range,Accept,x-ads-ul-ctx-workflow-id,x-requested-with,Expect,x-ads-acm-check-groups,If-None-Match,Content-Type,x-csrf-token","Type":3,"ContentType":null},{"Name":"Access-Control-Allow-Methods","Value":"POST,GET,OPTIONS,HEAD,PUT,DELETE,PATCH","Type":3,"ContentType":null},{"Name":"Access-Control-Allow-Origin","Value":"","Type":3,"ContentType":null },{"Name":"Strict-Transport-Security","Value":"max-age=31536000; includeSubDomains","Type":3,"ContentType":null},{"Name" :"Connection","Value":"keep-alive","Type":3,"ContentType":null},{"Name":"Content-Length","Value":"192","Type":3,"ContentType":null},{"Name":"Content-Type","Value":"application/json" ,"Type":3,"ContentType":null},{"Name":"Date","Value":"Wed, 11 Mar 2020 08:59:54 GMT","Type":3 ,"ContentType":null}],"ResponseStatus":1,"ErrorMessage":null,"ErrorException":null,"ProtocolVersion":{"_Major":1,"_Minor ":1,"_Build":-1,"_Revision":-1}}

    [HttpGet]
    [Route("api/forge/bim360/token/{tokenId}/container/{containerId}/item/{itemId}/version/{versionId}/title/{titleId}/description/{descriptionText}")]
    public async Task<IRestResponse> CreateDocumentIssueAsync(string tokenId, string containerId, string itemId, string versionId, string titleId, string descriptionText)
    {
        dynamic body = new JObject();
        body.data = new JObject();
        body.data.type = "issues";
        body.data.attributes = new JObject();
        body.data.attributes.title = titleId;
        body.data.attributes.description = descriptionText;
        body.data.attributes.status = "open";
        body.data.attributes.starting_version = versionId;
        body.data.attributes.target_urn = itemId;

        //Added by me for test attributes
        body.data.attributes.due_date = "2020-03-12T01:19:54.861Z";
        body.data.attributes.assigned_to = "U39JJWXNXF9J";
        body.data.attributes.owner = "U39JJWXNXF9J";
        //body.data.attributes.ng_issue_subtype_id = "";
        //body.data.attributes.ng_issue_type_id = "";
        //body.data.attributes.root_cause_id = "";
        //body.data.attributes.starting_version = "";
        //body.data.attributes.location_description = "Kitchen";

        //body.data.attributes.pushpin_attributes = new JObject();
        //body.data.attributes.pushpin_attributes.object_id = dbId;
        //body.data.attributes.pushpin_attributes.type = "TwoDVectorPushpin";
        //body.data.attributes.pushpin_attributes.created_doc_version = version;

        RestClient client = new RestClient(BASE_URL);
        RestRequest request = new RestRequest("/issues/v1/containers/{container_id}/quality-issues", RestSharp.Method.POST);
        request.AddHeader("Authorization", "Bearer " + tokenId);
        request.AddHeader("Content-Type", "application/vnd.api+json");
        request.AddParameter("container_id", containerId, ParameterType.UrlSegment);
        request.AddParameter("text/json", Newtonsoft.Json.JsonConvert.SerializeObject(body), ParameterType.RequestBody);

        var res = await client.ExecuteTaskAsync(request);

        return res;
    }

请检查:

  1. access to the BIM 360 account,我相信你有
  2. data:readdata:write 创建访问令牌时的范围
  3. 创建应用程序时启用 BIM 360 API

对于使用 Node 编写应用程序的任何人来说,在模型衍生 api 示例和设计自动化 api 示例中存在相当多的错误,即使范围设置正确。

在设计自动化 Node.js 教程的 execute work item section 中,我们看到了这一行:

await new ForgeAPI.ObjectsApi().copyTo(bucketKey, inputFileNameOSS, outputFileNameOSS, req.oauth_client, req.oauth_token);

Earlier in the tutorial,参数req.oauth_client定义了AuthClientTwoLegged对象上getCredentials()方法的return值。为我调用 copyTo 的结果是神秘的 AUTH-010 代码,我仍然定义了正确的范围。

解决方案

我不得不用我的应用程序的实际 client_id 替换 req.oauth_client。这适用于模型导数 API 和设计自动化 Api。

不幸的是,docs for the copyTo function 错误地将参数列为 oAuth2Client 类型,但事实并非如此;任何收到错误的人都只能猜测参数是什么,因为文档不会费心解释每个参数类型。

文档令人失望,github 文档和 npm 文档上都有很多错误和拼写错误 - 准备好在 Postman 教程之间花费大量时间 cross-checking,实用程序如oss-manager,以及 error-ridden 文档。