0

I am using Autodesk Forge Viewer (@types/forge-viewer) in a React (TypeScript) project to display files from Autodesk Construction Cloud (ACC). However, I am encountering a 401 error during viewer initialization or file loading, and the file cannot be displayed.

Relevant Code

const options = {
  api: 'derivativeV2',
  env: 'AutodeskProduction',
  accessToken: publicToken, // Token obtained via 3-legged authentication
};

window.Autodesk.Viewing.Initializer(options, () => {
  if (!viewerDivRef.current) return;
  const viewer = new window.Autodesk.Viewing.GuiViewer3D(viewerDivRef.current);
  viewer.start();
  const documentId = `urn:${urn}`; // urn is obtained as described below
  window.Autodesk.Viewing.Document.load(
    documentId,
    (doc) => {
      const defaultModel = doc.getRoot().getDefaultGeometry();
      if (defaultModel) {
        viewer.loadDocumentNode(doc, defaultModel);
      }
    },
    (err) => {
      console.error('Viewer load error:', err); // Here, 4 is returned
    }
  );
});
  • publicToken is an access token obtained via Autodesk 3-legged authentication (OAuth 2.0 Authorization Code Flow, valid and not expired).
  • The token scopes are viewables:read and data:read.
  • urn is obtained from the ACC API's item.versions[].relationships.derivatives.data.id (e.g., adsk.wipprod:dm.lineage:xxxxxx). The API response does not include the urn: prefix, so I add urn: when passing it to the Viewer.
  • I have confirmed that both the URN and token are obtained correctly.

Error Details

  • The error callback of window.Autodesk.Viewing.Document.load returns 4 (console.error('Viewer load error:', err);).
  • Also, a request to https://cdn.derivative.autodesk.com/derivativeservice/v2/manifest/... returns a 401 error, and the response header contains:

x-ads-troubleshooting: The input urn is not authorized. Not authorized to read|view|download the resource.

What I Have Tried

  • Re-obtaining the token
  • Confirming the token scopes (viewables:read and data:read)
  • Checking the URN format (with urn: prefix)

Question

  • What could be the cause in this case?
  • Is there any problem with how I am passing the token or initializing the Viewer?
  • Are there any other points I should check?

Any help would be greatly appreciated!

1
  • Are you using the same 3-legged token to do both; viewer initialization and getting the version item.versions[].relationships.derivatives.data.id ? Commented Sep 5 at 11:00

1 Answer 1

0

I consulted with the APS support desk and they gave me the solution. I was trying to display a file from Autodesk Construction Cloud (ACC) in the Japan region, which requires a special configuration.

I fixed the issue by following the instructions here: https://aps.autodesk.com/en/docs/viewer/v7/change_history/#id12.

// ...
window.Autodesk.Viewing.FeatureFlags.set('DS_ENDPOINTS', true); // Added this line
window.Autodesk.Viewing.Initializer(options, () => {
  if (!viewerDivRef.current) return;
  const viewer = new window.Autodesk.Viewing.GuiViewer3D(viewerDivRef.current);
  viewer.start();
// ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.