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

Unable to renew access token in preflight scripts due to missing URLSearchParams Constructor #196

Open
illeb opened this issue Sep 16, 2022 · 0 comments

Comments

@illeb
Copy link

illeb commented Sep 16, 2022

Hi, first of all, thanks for the awesome work you are putting in this project.

I am in the process of including a preflight script for the renewal of the access token used to secure the APIS of my application.
The authentication is provided by FusionAuth, and i should use the following API to perform the renewal.
Note the statement in the docs

Ensure you are sending these parameters as form encoded data in the request body, do not send these parameters in a query string.

Following that specification, i came up with the following solution:

const data = new URLSearchParams({
	refresh_token: explorer.environment.get("refresh_token"),
	client_id: explorer.environment.get("client_id"),
 	grant_type: 'refresh_token'
 });

const { access_token, expires_in } = await explorer.fetch("https://auth.myProvider.io/oauth2/token",
	{
		method: "POST",
		body: data
	},
).then((response) => response.json());

explorer.environment.set("token", access_token);
explorer.environment.set("token_expires_at", expires_in);

However, this code will not work because URLSearchParams it's not included in the explorer context: running it, it will always yield the error URLSearchParams is not a constructor.

Can URLSearchParams() be added in the context? (I guess FormData() could be added too)
Otherwise the renewal of token that relies on POST with form encoded data will be simply impossible.

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

No branches or pull requests

1 participant