Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Issue on FueAuth #133

Open
carlhussey opened this issue Jul 24, 2019 · 0 comments
Open

Issue on FueAuth #133

carlhussey opened this issue Jul 24, 2019 · 0 comments

Comments

@carlhussey
Copy link

carlhussey commented Jul 24, 2019

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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant