简体   繁体   中英

custom rest api have 403 error in magento

i have create a custom rest api in magento. it is working fine if i access via this code :

http://www.magentocommerce.com/api/rest/introduction.html

But when i want to access this using this url :

host/api/rest/datafeed/truedash_customers

it is give me an error :

403 Access denied

can any one tell me why this happen any help please......

1) Quick and dirty fix: in the file /app/code/core/Mage/Api2/Model/Auth.php, change the value of: DEFAULT_USER_TYPE = 'guest' to DEFAULT_USER_TYPE = 'admin'.

In the file /app/code/core/Mage/Api2/Model/Auth/Adapter.php, change this line from return (object) array('type' => Mage_Api2_Model_Auth::DEFAULT_USER_TYPE, 'id' => null); to this: return (object) array('type' => Mage_Api2_Model_Auth::DEFAULT_USER_TYPE, 'id' => '1');

This way the authentication system will not be broken.

2) Proper and long run fix: Override the two functionalities using the magento overriding mechanism to have a better solution in accordance to magento standards. This way the core files will be intact.

  1. Quick and dirty fix: in the file /app/code/core/Mage/Api2/Model/Auth.php , change the value of: DEFAULT_USER_TYPE = 'guest' to DEFAULT_USER_TYPE = 'admin' .

  2. In the file /app/code/core/Mage/Api2/Model/Auth/Adapter.php, change this line from

     return (object) array('type' => Mage_Api2_Model_Auth::DEFAULT_USER_TYPE, 'id' => null); 

    to this:

      return (object) array('type' => Mage_Api2_Model_Auth::DEFAULT_USER_TYPE, 'id' => '1'); 

This way the authentication system will not be broken.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM