How to use the forge-apis.AuthClientTwoLegged function in forge-apis

To help you get started, we’ve selected a few forge-apis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / forge-apis / forge-apis-tests.ts View on Github external
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
github cyrillef / extract.autodesk.io / server / forge-token.js View on Github external
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) ;
github cyrillef / extract.autodesk.io / server / forge-token.js View on Github external
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) ;
		})
	;
github Autodesk-Forge / models.autodesk.io / server / lmv-projects.js View on Github external
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 ;
github Autodesk-Forge / viewer-navigation.sample / server / token.js View on Github external
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);
		});
	}
github Autodesk-Forge / forge-rcdb.nodejs / src / server / api / services / ForgeSvc.js View on Github external
request2LeggedToken (scope) {

    const oAuth2TwoLegged = new Forge.AuthClientTwoLegged(
      this._config.oauth.clientId,
      this._config.oauth.clientSecret,
      Array.isArray(scope) ? scope : [scope])

    return oAuth2TwoLegged.authenticate()
  }
github cyrillef / extract.autodesk.io / server / bubble.js View on Github external
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) {
github Autodesk-Forge / models.autodesk.io / server / lmv-token.js View on Github external
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 () ;
		})
	;
} ;