Score:0

REST API 401 Unauthorized in user register JSON post

cn flag

I created a headless application using Drupal and Vue.js/Nuxt.js. I want anonymous users to register and Admin approves their subscription (the configuration for this is done).

I can't find a way to understand why. When I give the Access POST on User registration resource permission to anonymous users, I get a 401 Unauthorized status with the No authentication credentials provided. message using Postman or Axios. When I give the Administer users permission to anonymous users, the POST method works fine for me without the X-CSRF-Token in the header.

The anonymous users don't need any identification methods to access the registration form and send their information using /user/register?_format=hal_json. The Administer users permission will let any user display, edit, delete users using the server URL.

let userData = {
        "_links": {
          "type": {
            "href": "http://example.com/rest/type/user/user"
          }
        },
        "name": [{"value": "jack"}],
        "mail": [{"value": "[email protected]"}],
        "field_phone": [{"value": "99999999"}],
        "roles": [{"target_id": "member"}],
        //"pass": [{"value": "0000"}] // if required email verification (admin/config/people/accounts) not checked we send pass
      };

 // Post Data
      this.$axios.post("http://example.com/user/register?_format=hal_json", userData, {
        headers: {
          "Content-type": "application/hal+json"
        }
      }).then(() => {
      }).catch(function (res) {
      });

I also tried to remove the Administer users permission from anonymous users and add the X-CSRF-Token header with a value from www.example.com/session/token, but I still get the No authentication credentials provided. message.

user registration configuration

account configuration

"Administer users" permission

"Access POST on User registration resource" permission

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.