This example wraps the asynchronous method oauth2.client.getToken(callback)
from the package NPM package simple-oauth2
into a Fiber so that the method may be called synchronously.
const oauth2 = require('simple-oauth2')(credentials);
const credentials = {
clientID: '#####',
clientSecret: '#####',
site: "API Endpoint Here."
};
Meteor.startup(() => {
let token = Meteor.wrapAsync(oauth2.client.getToken)({});
if (token) {
let headers = {
'Content-Type': "application/json",
'Authorization': `Bearer ${token.access_token}`
}
// Make use of requested OAuth2 Token Here (Meteor HTTP.get).
}
});