This sample is demonstrating how to host a proxy server to forward all requests from the Forge Viewer to this backend without showing access token in your viewer frontend.
- node.js v8.9.4 or later
- Download and install Node.js (that will install npm as well)
- Download this repo anywhere you want
- Execute 'npm install', this command will download and install the required node modules automatically for you.
npm install
Before starting the server, you have to set the Forge credentials up.
-
Mac OSX/Linux (Terminal)
export FORGE_CLIENT_ID=<<YOUR_CLIENT_ID_FROM_DEVELOPER_PORTAL>> export FORGE_CLIENT_SECRET=<<YOUR_CLIENT_SECRET>>
-
Windows (use Node.js command line from Start menu)
set FORGE_CLIENT_ID=<<YOUR_CLIENT_ID_FROM_DEVELOPER_PORTAL>> set FORGE_CLIENT_SECRET=<<YOUR_CLIENT_SECRET>>
-
Windows (use Powershell from Start menu)
$env:FORGE_CLIENT_ID="<<YOUR_CLIENT_ID_FROM_DEVELOPER_PORTAL>>" $env:FORGE_CLIENT_SECRET="<<YOUR_CLIENT_SECRET>>"
Then Run the server
npm start
- Configure viewer endpoint Initialize your viewer app in this way:
const options = {
env: 'AutodeskProduction',
accessToken: 'eyJhbGciOiJIUzI1NiIsImtpZCI6Imp3dF9zeW1tZXRyaWNfa2V5X2RldiJ9.eyJjbGllbnRfaWQiOiJjWTFqcm1rQXhPSVptbnNsOVhYN0puVURtVEVETGNGeCIsImV4cCI6MTQ4NzU2NzgwMSwic2NvcGUiOlsiZGF0YTpyZWFkIl0sImF1ZCI6Imh0dHBzOi8vYXV0b2Rlc2suY29tL2F1ZC9qd3RleHAzMCIsImp0aSI6InJZcEZZTURyemtMOWZ1ZFdKSVVlVkxucGNWT29BTDg0dFpKbXlmZ29ORW1MakF0YVVtWktRWU1lYUR2UGlnNGsifQ.uzNexXCeu4efGPKGGhHdKxoJDXHAzLb28B2nSjrq_ys' //!<<< Pass a expired token to avoid initializing auth issue on the Forge Viewer v7.x
};
Autodesk.Viewing.Initializer( options, () => {
// Change derivative endpoint to Proxy endpoint
Autodesk.Viewing.endpoint.setApiEndpoint( 'http://127.0.0.1:8085/forge-proxy', 'derivativeV2' );
Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
});
This sample is licensed under the terms of the MIT License. Please see the LICENSE file for full details.
Eason Kang
Forge Partner Development
https://developer.autodesk.com/
https://forge.autodesk.com/blog