-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,54 @@ | ||
const authServer = require('./server'); | ||
|
||
const ForgeSDK = require('forge-apis'); | ||
/* | ||
Look at this for fetching new auth tokens in a loop: | ||
https://nodejs.org/en/docs/guides/timers-in-node/ | ||
*/ | ||
|
||
function intervalFunc() { | ||
console.log('Running every 15 sec'); | ||
cr = authServer.getCredentials(); | ||
console.log(cr); | ||
console.log(authServer.authClient); | ||
var hasCredentials = false; | ||
var credentials; | ||
var authClient = authServer.authClient; | ||
|
||
var HubsApi = new ForgeSDK.HubsApi(); //Hubs Client | ||
var BucketsApi = new ForgeSDK.BucketsApi(); //Buckets Client | ||
|
||
async function waitUntil(hasCredentials) { | ||
return await new Promise(resolve => { | ||
const interval = setInterval(() => { | ||
console.log('Running every 5 sec, waiting for browser authorization at localhost:3000/auth'); | ||
hasCredentials = authServer.getCredentials(); | ||
if (hasCredentials != undefined) { | ||
credentials = hasCredentials; | ||
resolve('credentials recieved'); | ||
clearInterval(interval); | ||
}; | ||
}, 5000); | ||
}); | ||
} | ||
|
||
|
||
(async () => { | ||
// create the server | ||
let server = await authServer.create(); | ||
})(); | ||
|
||
// wait until user authenticates through browser | ||
await waitUntil(hasCredentials); | ||
|
||
// cannot shutdown the server becuase it is running on the same thread, doing this will just kill the node process (i.e. test.js) | ||
// authServer.shutdown(server); | ||
|
||
console.log("Authenticated"); | ||
// console.log(credentials); | ||
// console.log(authClient); | ||
|
||
/* | ||
Testing setInterval function, will likely need to use this for refreshing auth tokens | ||
*/ | ||
setInterval(intervalFunc, 15000); | ||
|
||
|
||
// Can do use forge APIs now, using credentials and authClient | ||
|
||
// testing | ||
HubsApi.getHubs({}, authClient, credentials).then(function(hubs) { | ||
console.log(hubs.body.data); | ||
}, function(err){ | ||
console.error(err); | ||
}); | ||
})(); |