autodesk-forgeautodesk-viewerautodeskautodesk-model-derivativeforge

Autodesk Forge Viewer : Using translated urn from one application in another application?


I have an Angular Application, and I was trying to integrate Autodesk Forge Viewer into my Application, for that first I created a Sample Application following the URL (https://learnforge.autodesk.io/#/tutorials/viewmodels) and I was able to view the drawing in the Forge viewer, then to check the feasibility while I integrate the forge Viewer into my application I followed the following steps:

Here the following is the translated urn I got from my sample Application: “dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6eXlpYnFqdW8yeW9yNTF2c2d2Y3VzcHlnbnk5amVhbnQtdmxmbTIyL0RDLUhRLTAxQVIlMjAoMTMpLmR3Zw” so I used this particular urn for viewing the drawing in my application also, and the code is as shared below:

var contextObj = this;
    var urn = "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6eXlpYnFqdW8yeW9yNTF2c2d2Y3VzcHlnbnk5amVhbnQtdmxmbTIyL0RDLUhRLTAxQVIlMjAoMTMpLmR3Zw";
    this.objiWhiz.Token(function (resCallback) {
    contextObj.token = resCallback;
     var access_token = contextObj.token;
     jQuery.ajax({
         url: 'https://developer.api.autodesk.com/modelderivative/v2/designdata/' + urn + '/manifest',
         headers: { 'Authorization': 'Bearer ' + access_token },
         success: function (res) {
          if (res.status === 'success')
                    this.launchViewer(urn);
                 },
          error: function (err) {
                 console.log("not sucessfull");
                 }
        });
// using the Token Function I was able to get the access_token,

this.Token = function (resCallback) {
   try {
       var that = this;
       var data = "12";   //   ViewablesRead = 12
       $.ajax({
           url:  '/6.8/api/iWhiz/Get2LeggedTokenAsync',
           type: "POST",
           headers: {  "__RequestVerificationToken": that.m_csrfToken },
          data: JSON.stringify([data]),
          contentType: 'application/json; charset=utf-8',
          success: function (returnObject) {
               resCallback(returnObject.access_token);                 
               }
         });
   }

   catch (e) {
       resCallback(9);
   }
 },
public async Task<dynamic> Get2LeggedTokenAsync(List<string> Val)

   {

       TwoLeggedApi oauth = new TwoLeggedApi();

       string grantType = "client_credentials";

       dynamic bearer = await oauth.AuthenticateAsync(

        "FORGE_CLIENT_ID","FORGE_CLIENT_SECRET"

         grantType,

         new Scope[] { Scope.DataWrite });

       return bearer;
}

GET https://developer.api.autodesk.com/modelderivative/v2/designdata/dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6eXlpYnFqdW8yeW9yNTF2c2d2Y3VzcHlnbnk5amVhbnQtdmxmbTIyL0RDLUhRLTAxQVIlMjAoMTMpLmR3Zw/manifest 403 (Forbidden)

and when I click the URL: https://developer.api.autodesk.com/modelderivative/v2/designdata/dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6eXlpYnFqdW8yeW9yNTF2c2d2Y3VzcHlnbnk5amVhbnQtdmxmbTIyL0RDLUhRLTAxQVIlMjAoMTMpLmR3Zw/manifest

I am getting the message: { "developerMessage":"Token is not provided in the request.", "moreInfo": "https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/", "errorCode": "AUTH-010"}


Solution

  • The scope you specified when requesting the access token is data:write only, which is incorrect. To access the translated result, you need either data:read or viewables:read. See https://forge.autodesk.com/en/docs/model-derivative/v2/reference/http/manifest/urn-manifest-GET/

    public async Task<dynamic> Get2LeggedTokenAsync(List<string> Val)
     
           {
     
               TwoLeggedApi oauth = new TwoLeggedApi();
     
               string grantType = "client_credentials";
     
               dynamic bearer = await oauth.AuthenticateAsync(
     
                "FORGE_CLIENT_ID","FORGE_CLIENT_SECRET"
     
                 grantType,
     
                 new Scope[] { Scope.ViewablesRead });
                 // new Scope[] { Scope.DataRead });
     
               return bearer;
    }