headless-drupal-angular icon indicating copy to clipboard operation
headless-drupal-angular copied to clipboard

http://local.drupal8-host.dev:8000/node/2 401 (Unauthorized)

Open iamstoick opened this issue 11 years ago • 3 comments

I am getting this error http://local.drupal8-host.dev:8000/node/2 401 (Unauthorized).Any idea what's is wrong with my setup? Basically I just followed the instructions on README.

I am not sure if I understand #3 Copy in the provided rest.settings.yml configuration. though.

iamstoick avatar Nov 19 '14 07:11 iamstoick

Couldn't tell you specifically, but it's a good opportunity to learn more about how HTTP routing and authorization works in D8! :)

joshkoenig avatar Nov 19 '14 16:11 joshkoenig

@geraldvillorente I ran into this same issue with my local D8 setup. It turned out to be a CORS issue.

Chrome console: XMLHttpRequest cannot load http://d8rest.local/node/1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3333' is therefore not allowed access.

I run nginx locally, so I was able to add one line in nginx.conf to bypass CORS. Be aware this is not a secure solution for a live web site but works fine for local development. For nginx, place this line somewhere in your nginx.conf server { } block:

add_header "Access-Control-Allow-Origin" $http_origin;

For Apache, see this article which includes a patch to .htaccess to bypass CORS restrictions.

pxwise avatar Dec 02 '14 08:12 pxwise

To answer the original question a little bit. After enabling the rest modules, enable permissions for the Anon user or authenticated user depending on what access you want for the GET, POST, PATCH, DELETE operations.

Using the Rest UI module adds a GUI to set the Rest configuration instead of using the rest.settings.yml file.

kamkejj avatar Feb 13 '15 19:02 kamkejj