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
}
);
});
publicTokenis an access token obtained via Autodesk 3-legged authentication (OAuth 2.0 Authorization Code Flow, valid and not expired).- The token scopes are
viewables:readanddata: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.loadreturns4(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:readanddata: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!