FuelSDK-Node-SOAP
FuelSDK-Node-SOAP copied to clipboard
Issue on FueAuth
I am using FuelSoap with FuelAuth and running into an issue on setting up the client.
var FuelAuthClient = new FuelAuth({
clientId: clientId,
clientSecret: clientSecret,
authUrl: authOrigin,
authOptions: {
authVersion: 2
}
});
FuelAuthClient.getAccessToken()
.then(function (data) {
// data.accessToken = your token
// data.expiresIn = how long until token expiration
console.log(data);
var SoapClient = new FuelSoap(FuelAuthClient);
SoapClient.retrieve(
'Email',
["ID", "Name", "Subject", "CategoryID", "EmailType"],
options,
function (err, response) {
if (err) {
// error here
console.log(err);
return;
}
// response.body === parsed soap response (JSON)
// response.res === full response from request client
console.log(response.body);
}
)
})
.catch(function (err) {
console.log(err);
});
The issue I am facing is in the FuelSoap
initialization where it checks to see if its an instance of FuelAuth
.
var authOptions = options && options.auth || {};
// use fuel auth instance if applicable
if(authOptions instanceof FuelAuth) {
this.AuthClient = authOptions;
} else {
try {
this.AuthClient = new FuelAuth(authOptions);
} catch (err) {
throw err;
}
}```
It looks like this line `var authOptions = options && options.auth || {};` is creating an empty object, expecting that `options.auth` exists. Well, when using the `FuelAuth` object, thats not the case so it defaults `authOptions = {}`.
This causes the `if(authOptions instanceof FuelAuth) {` to return false and it tries to initialize `FuelAuth` using the `authOptions` which is an empty object. This throws an error in `FuelAuth` about `Error: clientId or clientSecret is missing or invalid`.
To summarize, `if(authOptions instanceof FuelAuth) {` returns false when using `FuelAuth` because `options.auth` doesn't exist which causes `authOptions` to be set to an empty object.