0

I have a custom module to create a custom Rest API resource. I want to remove the authentication and make it without required authentication. In my file custom_moudle/config/install/rest.resource.custom_resource.yml

this is my code

id: custom_resource
plugin_id: custom_resource
granularity: method
configuration:
  GET:
    supported_formats:
      - json
    supported_auth:
      - basic_auth

This is working fine but with authentication. When trying to remove this lines

supported_auth:
  - basic_auth

I got an error. So what is the correct way to remove this authentication?

2 Answers 2

1

REST module plugins must have an authentication plugin. Try using the cookie plugin, which is the default one that core uses.

1
  • There's not much to use. You just set it and it re-uses the default session cookie. Apr 18, 2018 at 23:51
0

You can skip the authentication for any rest API by Altering the route of that rest resource. there are various examples available on the web.

      /**
       * {@inheritdoc}
       */
      protected function alterRoutes(RouteCollection $collection) {
        if ($route = $collection->get('rest.lost_password_resource.POST')) {
          $requirements = $route->getRequirements();
          if (!empty($requirements['_csrf_request_header_token'])) {
            unset($requirements['_csrf_request_header_token']);
            unset($requirements['_permission']);
            $options = $route->getOptions();
            unset($options['_auth']);
            $route->setOptions($options);
            $route->setRequirements($requirements);
          }
        }
     }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.