Skip to content

Making any API call using React is unsupported #82

@ofekkazes

Description

@ofekkazes

Hi,

For the past few hours I started using the Pfsense API and noted some issues with a React.js application.
Every call being made, with all the headers required returns a response with missing CORS policies.
Basic Call

Adding a CORS extension to allow some policies from the browser had issued a different error which might be helpful in identifying the source.

CORs Extension

So it seems like the the issue is most likely connected to having some kind of protection from browser POST javascript calls.
As React.js and other frameworks now use front-end applications with remote APIs and callbacks it might be good to change that protection.

Its worth noting that I'm using pfsense via a remote VM, with the React application in my local PC running on Google Chrome.

Below is my basic request for a token from the API.

login: ({ username, password }) => { const headers = new Headers(); headers.append('Content-Type', 'application/json'); headers.append("Host", "http://172.31.0.25"); headers.append("Origin", "http://localhost:3000/"); const request = new Request('http://172.31.0.25/api/v1/access_token', { method: "POST", body: JSON.stringify({ "client-id": username, "client-token": password }), headers: headers, }); console.log(request); return fetch(request) .then(response => { if (response.status < 200 || response.status >= 300) { throw new Error(response.statusText); } return response.json(); }) .then(auth => { console.log(auth); localStorage.setItem('auth', JSON.stringify(auth)); }) .catch(() => { throw new Error('Network error') }); }

Is there something that can be done?

Thank you
Ofek

Metadata

Metadata

Labels

documentationImprovements or additions to documentationfeature requestNew feature or requestneeds researchIssues that require further research

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions