Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also support object parameter and fix optionals #37

Closed
wants to merge 1 commit into from

Conversation

ianwensink
Copy link

@ianwensink ianwensink commented Sep 2, 2020

Both the constructor of FusionAuthClient and its exchangeOAuthCodeForAccessToken now also support calling them with an object instead of separate parameters.

This helps when a lot of the parameters are optional (as per the docs).

Completely backwards compatible.

This fixes #36 & makes progress on #29, but I've only amended the methods I needed right now. Feel free to work on it by implementing this for more methods. Also the jsdocs should be amended still. I'd say this could be merged (if approved) already, and make the new approach gradually available.

Examples

This is how the constructor used to work

const client = new FusionAuthClient(
  'WRONGLY REQUIRED API KEY',
  'REQUIRED HOST',
  'OPTIONAL TENANT ID'
);

But the docs state (see Examples) you can leave out the API KEY if you don't want it (in the frontend, e.g.). This isn't true as per the types, so I fixed that by introducing the object. This would look like this. You can leave out the key if you don't want it.

const client = new FusionAuthClient({ host: 'REQUIRED HOST' });

The same goes for exchangeOAuthCodeForAccessToken.

const client = new FusionAuthClient({ host: 'REQUIRED HOST' });

client.exchangeOAuthCodeForAccessToken(
  'REQUIRED CODE',
  'WRONGLY REQUIRED CLIENT ID',
  'WRONGLY REQUIRED CLIENT SECRET',
  'REQUIRED REDIRECT URI'
);

Becomes the following, since only the code and redirect_uri are actually required.

const client = new FusionAuthClient({ host: 'REQUIRED HOST' });

client.exchangeOAuthCodeForAccessToken({ code: 'REQUIRED CODE', redirect_uri: 'REQUIRED REDIRECT URI' });

Both the constructor of FusionAuthClient and its exchangeOAuthCodeForAccessToken now also support calling them with an object instead of separate parameters. This helps when a lot of the parameters are optional (as per the docs). Completely backwards compatible.

FusionAuth#29 & FusionAuth#36
@alex-fusionauth
Copy link

Closing so that the new codebase is set in #102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Passing configuration object to FusionAuthClient 🤔
2 participants