forge-apis
Version:
⚠️ Deprecated: This package is no longer maintained. Use 'https://github.com/autodesk-platform-services/aps-sdk-node' instead.
94 lines (81 loc) • 4.09 kB
JavaScript
//
// Copyright (c) 2019 Autodesk, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
/*jshint esversion: 9 */
const ForgeSDK = require('./../src/index');
// TODO - insert your CLIENT_ID and CLIENT_SECRET
const APS_CLIENT_ID = process.env.APS_CLIENT_ID || 'your forge client id';
const APS_CLIENT_SECRET = process.env.APS_CLIENT_SECRET || 'your forge client secret';
// Initialize the 2-legged oauth2 client
const oAuth2TwoLeggedV2 = new ForgeSDK.AuthClientTwoLeggedV2(APS_CLIENT_ID, APS_CLIENT_SECRET,
['data:read'], true);
const oAuth = new ForgeSDK.AuthClientTwoLeggedV2(APS_CLIENT_ID, APS_CLIENT_SECRET,
['data:read', '*'], false);
// oAuth2TwoLegged.authenticate()
// .then((credentials) => {
// console.log("**** Got Credentials", credentials);
// })
// .catch (err => {
// console.error('\x1b[31m Error:', err, '\x1b[0m');
// });
(async () => {
try {
let credentials = await oAuth.authenticate({'region': 'IND'});
console.log("**** Got Credentials", JSON.stringify(credentials, null, 4));
const result = await oAuth.verifyToken(credentials.access_token);
console.log("**** Credentials verified", JSON.stringify(result, null, 4));
} catch (ex) {
console.error('\x1b[31m Error:', ex, '\x1b[0m');
}
})();
// curl -v 'https://developer.api.autodesk.com/authentication/v2/token' \
// -X 'POST' \
// -H 'Authorization: Basic eFpTWHBzUnI3OXdXZE90cTN5SGh0SXlpQ0VNVGlHVkI6UzRaQ0dRZDRod0ZwMWE5Wg==' \
// -H 'Content-Type: application/x-www-form-urlencoded' \
// -H 'Accept: application/json' \
// -H 'region: IND' \
// -d 'grant_type=client_credentials' \
// -d 'scope=data:read wipdm:data:write wipdm:data:read *'
// curl -v 'https://developer.api.autodesk.com/authentication/v2/token' \
// -X 'POST' \
// -H 'Authorization: Basic eFpTWHBzUnI3OXdXZE90cTN5SGh0SXlpQ0VNVGlHVkI6UzRaQ0dRZDRod0ZwMWE5Wg==' \
// -H 'Accept: application/json' \
// -H 'Content-Type: application/x-www-form-urlencoded' \
// -d 'grant_type=client_credentials' \
// -d 'scope=data:read'
// Akhil
// 3EGB8J8YIu9bE4kgFgtJQUoqHOzIaVSxCIGj9D0Haqq0yUer
// 0p9KVeOSG1hGQJOPaR3G7FJcOnlsX4QrWpSX2uh1srYMSX1GO1Op62nGHvoMa7py
// curl -v 'https://developer-stg.api.autodesk.com/authentication/v2/token' \
// -X 'POST' \
// -H 'Authorization: Basic M0VHQjhKOFlJdTliRTRrZ0ZndEpRVW9xSE96SWFWU3hDSUdqOUQwSGFxcTB5VWVyOjBwOUtWZU9TRzFoR1FKT1BhUjNHN0ZKY09ubHNYNFFyV3BTWDJ1aDFzcllNU1gxR08xT3A2Mm5HSHZvTWE3cHk=' \
// -H 'Content-Type: application/x-www-form-urlencoded' \
// -H 'Accept: application/json' \
// -H 'region: IND' \
// -d 'grant_type=client_credentials' \
// -d 'scope=data:read data:write data:create data:search account:read *'
// curl -v 'https://developer-stg.api.autodesk.com/authentication/v2/token' \
// -X 'POST' \
// -H 'Authorization: Basic M0VHQjhKOFlJdTliRTRrZ0ZndEpRVW9xSE96SWFWU3hDSUdqOUQwSGFxcTB5VWVyOjBwOUtWZU9TRzFoR1FKT1BhUjNHN0ZKY09ubHNYNFFyV3BTWDJ1aDFzcllNU1gxR08xT3A2Mm5HSHZvTWE3cHk=' \
// -H 'Accept: application/json' \
// -H 'Content-Type: application/x-www-form-urlencoded' \
// -d 'grant_type=client_credentials' \
// -d 'scope=data:read'