Autodesk-forge 查看器:访问令牌

Autodesk-forge viewer: Access token

我正在按照 Forge 教程将 Forge 查看器嵌入 html 页面。 我最终来到了这个伪造的页面,link:https://autodesk-forge.github.io/forge-tutorial-postman/display_svf.html 我了解如何使用 cURL 检索访问令牌,但我想修改该网站,这样我就不必自己输入访问令牌。 我希望 cURL 响应中的访问令牌自动导入为该网站的访问令牌。这怎么可能。 该网页的代码在这里:https://github.com/Autodesk-Forge/forge-tutorial-postman/blob/master/docs/display_svf.html 当我在网页上点击提交时,如何添加 function/method 以自动检索访问令牌。 非常感谢任何帮助! 干杯!

您要查找的服务器端代码是:

app.get('/api/forge/oauth', function (req, res) {
    Axios({
        method: 'POST',
        url: 'https://developer.api.autodesk.com/authentication/v1/authenticate',
        headers: {
            'content-type': 'application/x-www-form-urlencoded',
        },
        data: querystring.stringify({
            client_id: FORGE_CLIENT_ID,
            client_secret: FORGE_CLIENT_SECRET,
            grant_type: 'client_credentials',
            scope: scopes
        })
    })
        .then(function (response) {
            // Success
            access_token = response.data.access_token;
            console.log(response);
            res.send('<p>Authentication success!</p>');
        })
        .catch(function (error) {
            // Failed
            console.log(error);
            res.send('Failed to authenticate');
        });
});

请参考Forge 2-Legged Authentication tutorials for the code and more details. We also have more tutorials and workflow on Learn Autodesk Forge.