I need to make some endpoints private on node, at the moment I’m in a homologation process of publishing the app and I need to make creation/edit/delete endpoints private so other users can’t call or access them without credentials essentially.
I’m told on the thread to use Authorization header using https://app.io.vtex.com/{{vendor.app_name}}/v0/{{VTEX_ACCOUNT}}/{{WORKSPACE}}/_v/ENDPOINT_URL
As I understood this TOKEN is VtexIdclientAutCookie on the header which we extract from ctx.vtex.authToken
I’m calling from the vtex react app the URL represented above and it gives me CORS 401 error, also I tried to implement it directly into node but this doesn’t seem a good solution because I have to set it into communication between vtex react app (admin) to node (vtex server side) which communicates with masterdata.
Tried to call the same API from Postman and it says [my email] doesn’t have access to the GET resource and it outputed the vrn: address from AWS, I’ve got Super Admin access and I’ve checked that all the resources on this role are available.
Can you please help me on this? Maybe anyone of you encountered this problem?
I have a question, does the request fail inside one of your middlewares for that endpoint? Or it fails before that?
Maybe is something related to the endpoint itself, the one you declare inside your service.json.
When a REST endpoint is private you should declare the policies for it. Here is an example:
In the example above, that private endpoint is declared in my node app and the only thing that can access that endpoint with a GET request is my frontend app (declared with the VRN in the principals)
I’ve tried to set the police you’ve sent and it didn’t work, it kept saying Forbidden, I’ve tried to change the form of principals as it is written inside the error and no luck, tried both ways.
I belive that the token you are trying to use may not be the right one. I think that the token you are using is related to you as a client of the store and not as the one as an admin (not sure tho )
I suggest you try this:
Try making that request without the Authorization (removing that param you send) to see if the error persists.
We can test the token, try to make the request with the VtexIdclientAutCookie , you can find that token in the cookies after you login into the admin.
BUT I’ve tried to set on axios header from rect { withCredentials: true } and somehow I’ve got an update from 401 error saying that * I should use something different from *
what can I set? having this:
It’s failing before middleware, if I will pass service.json I’ll get into middleware and will get as output consoles in terminal, but it doesn’t happen
It’s failing right on CORS between node gate and react gate
CORS policy: Response to preflight request doesn’t pass access control check: The value of the ‘Access-Control-Allow-Origin’ header in the response must not be the wildcard '’ when the request’s credentials mode is ‘include’*
Update I saw some requests having 200 OK, have you tried on these timings?
Just a wild guess: Try to add user:xx.xxx@productlead.me in the principals. I am sure it´s not going to work in production, but might work with Postman.
When I call with productlead–productleadpartnerro… it says that endpoint is not found (404), tried to use user in principals and nothin changed in postman nor in react client
Update: If I set principals: ["*"] it works from POSTMAN to request, but it doesn’t work inside vtex admin to request, it keeps the CORS error