Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ObjectsApi,
ProjectsApi,
UserProfileApi,
VersionsApi,
WorkItemsApi,
} from 'forge-apis';
const authToken: AuthToken = {
access_token: '',
expires_in: 0,
token_type: '',
refresh_token: '',
};
// $ExpectType AuthClientTwoLegged
const authClientTwoLegged = new AuthClientTwoLegged('', '', [], true);
// $ExpectType Promise
authClientTwoLegged.authenticate();
// $ExpectType AuthToken
authClientTwoLegged.getCredentials();
// $ExpectType void
authClientTwoLegged.setCredentials(authToken);
// $ExpectType boolean
authClientTwoLegged.isAuthorized();
// $ExpectType AuthClientThreeLegged
const authClientThreeLegged = new AuthClientThreeLegged('', '', '', [], true);
// $ExpectType string
authClientThreeLegged.generateAuthUrl();
// $ExpectType Promise
authClientThreeLegged.getToken('');
// $ExpectType Promise
var refreshToken =function (credentials) {
credentials =credentials || config.credentials ;
if ( oAuth2TwoLegged === null )
oAuth2TwoLegged =new ForgeSDK.AuthClientTwoLegged (credentials.client_id, credentials.client_secret, credentials.scope) ;
oAuth2TwoLegged.authenticate ()
.then (function (response) {
console.log ('Token: ' + response.access_token) ;
oAuth2TwoLegged.setCredentials (response) ;
setTimeout (refreshToken, (response.expires_in - 300) * 1000) ; // - 5 minutes
utils.writeFile (utils.data ('token'), response)
.catch (function (err) {
throw err ;
}) ;
createApplicationBucket () ;
rebuildBucketContent () ;
})
.catch (function (error) {
setTimeout (refreshToken, 2000) ; // Try again
utils.unlink (utils.data ('token')) ;
console.error ('Token: ERROR! ', error) ;
var refreshTokenRO =function (credentials) {
credentials =credentials || config.credentials ;
if ( oAuth2TwoLeggedRO === null )
oAuth2TwoLeggedRO =new ForgeSDK.AuthClientTwoLegged (credentials.client_id, credentials.client_secret, [ 'data:read' ]) ;
oAuth2TwoLeggedRO.authenticate ()
.then (function (response) {
console.log ('Token RO: ' + response.access_token) ;
oAuth2TwoLeggedRO.setCredentials (response) ;
setTimeout (refreshTokenRO, (response.expires_in - 300) * 1000) ; // - 5 minutes
utils.writeFile (utils.data ('tokenRO'), response)
.catch (function (err) {
throw err ;
}) ;
})
.catch (function (error) {
setTimeout (refreshTokenRO, 2000) ; // Try again
utils.unlink (utils.data ('tokenRO')) ;
console.log ('Token RO: ERROR!', error) ;
})
;
router.post ('/translate', function (req, res) {
var accessToken =req.body.accessToken ;
var filename =_path.normalize (__dirname + '/../' + req.body.file) ;
var hash =crypto.createHash ('md5').update (config.credentials.client_id).digest ('hex').replace (/\W+/g, '') ;
var bucketKey =
'model'
+ new Date ().toISOString ().replace (/T/, '-').replace (/:+/g, '-').replace (/\..+/, '')
+ '-' + hash ;
var oAuth2 =new ForgeApis.AuthClientTwoLegged ('', '', config.credentials.scope) ;
oAuth2.setCredentials ({
access_token: accessToken,
type: 'Bearer',
expires_at: 3599,
}) ;
var size ;
filesize(filename)
.then (function (results) {
size =results ;
return (ExistOrCreate (bucketKey, oAuth2)) ;
})
.then (function (bucket) {
console.log ('async upload') ;
var total =size ;
//var chunkSize =config.fileResumableChunk * 1024 * 1024 ;
getTokenPublic (callback) {
let clientId = config.get('credentials.client_id') || process.env.FORGE_CLIENT_ID;
let clientSecret = config.get('credentials.client_secret') || process.env.FORGE_CLIENT_SECRET;
let apiInstance = new ForgeSDK.AuthClientTwoLegged(clientId, clientSecret, config.get('scopePublic'), config.get('autoRefresh'));
apiInstance.authenticate().then(function (data) {
callback(data, apiInstance);
});
}
request2LeggedToken (scope) {
const oAuth2TwoLegged = new Forge.AuthClientTwoLegged(
this._config.oauth.clientId,
this._config.oauth.clientSecret,
Array.isArray(scope) ? scope : [scope])
return oAuth2TwoLegged.authenticate()
}
this.downloadBubble =function (urn, outPath, token) {
var self =this ;
if ( token ) {
self._token =new ForgeSDK.AuthClientTwoLegged ('__', '__', [ 'data:read' ]) ;
self._token.setCredentials ({
'token_type': 'Bearer',
'expires_in': 1799,
'access_token': token
}) ;
} else {
self._token =forgeToken.RW ;
}
self._outPath =outPath ;
return (new Promise (function (fulfill, reject) {
self._progress.msg ='Downloading manifest' ;
self.getManifest (urn)
.then (function (bubble) {
//utils.writeFile (outPath + 'bubble.json', bubble) ;
self._progress.msg ='Listing all derivative files' ;
self.listAllDerivativeFiles (bubble.body, function (error, result) {
var refreshToken =function (credentials, res) {
var oAuth2 =new ForgeApis.AuthClientTwoLegged (credentials.client_id, credentials.client_secret, credentials.scope) ;
oAuth2.authenticate ()
.then (function (response) {
res.json (response) ;
})
.catch (function (error) {
if ( error.statusCode || error.errorCode )
return (res.status(error.statusCode || 401).end(error.statusMessage || error.developerMessage));
res.status (500).end () ;
})
;
} ;