How to Override REST Authentication in Magento 2 platform?

Learn how to override the REST API authentication in Magento 2 platform in a few steps here:

Nowadays’s REST authentication API become well-known in Magento 2. To send a request to REST requires a resource to give permission to access data or process a logic code.

Build your Amazon-like multi-vendor marketplace website @ $249/- now!!!
              Get your free live demo now: Click here

Override REST authentication in Magento 2 platform

Here, I will show you how to override REST authentication, so you can create your custom authentication.

  • Create a di.xml file :
<?xml version="1.0" encoding="UTF-8"?>

 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

   <preference for="Magento\Webapi\Controller\Rest" type="Webnexs\Training\Controller\Rest"/>

 </config>
  • After that, create a file to handle the rewrite.
<?php

 namespace Webnexs\Training\Controller;

 use Magento\Framework\Exception\AuthorizationException;

 use Magento\Framework\Webapi\Rest\Request as RestRequest;

 use Magento\Framework\Webapi\Rest\Response as RestResponse; use Magento\Framework\Webapi\Rest\Response\FieldsFilter;

 use Magento\Webapi\Controller\Rest\Router;

 class Rest extends \Magento\Webapi\Controller\Rest

 {

   protected function checkPermissions()

  {

    //Todo

   }

 }

Write the code to check the //Todo.

After that refresh the cache to make it work.

I hope that the above mention guideline helps you to override the REST authentication in the Magento platform.

Contact Webnexs to develop an online store with the Magento platform today!!!

Override REST authentication in Magento 2


Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *