Jump to content

How to generate/get AdminProducts token in PrestaShop 1.7.x


Recommended Posts

Hi

I am trying to develop a module to help list products in various situations. How do I generate a token for at direct product link with PS 1.7.x? I can't seem to find any examples that helps.

I can generate tokens for customers and other stuff which works - and those tokens seems to be md5, but the tokens for AdminProducts seems to be another type of hash, like "HK5Z6KMpx_EP6-ykNM2Ju1QAkOqlFmskolAe3IXt8ss". Any help anyone?

Thanks for your answer.

Link to comment
Share on other sites

  • 2 weeks later...
  • 9 months later...

Hello, can anyone provide some informations on this subject? I saw some solutions similar to

 

$tokenProducts = Tools::getAdminToken(
            'AdminProducts'.
            (int)Tab::getIdFromClassName('AdminProducts').
            (int)$this->context->employee->id
        );

 

but the code I receive is always different from the one i see in the url in my browser after the _token parameter: index.php/product/catalog?_token=DIFFERENT_CODE_HERE

 

Edit: nevermind, have a look here.

Edited by Uff182 (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 10 months later...
  • 10 months later...

I have a issue I am stuck on for 3 days now.

I created a controller in a module (modulename/src/Controller) with the new Symfony system :

class TestController extends FrameworkBundleAdminController
{
    public static function getTest(){
        return new JsonResponse("test);
    }
}

And then declared the route in routes.yml as following:

getTest:
  path: mymodule/gettest
  methods: [GET]
  defaults:
    _controller: 'Mymodule\Controller\TestController::getTest'

When I call the URI adminfolder/modules/mymodule/gettest everything works fine but ONLY if i have the token of the module list page "http://...../adminfolder/index.php/improve/modules/manage"

The aim of this controller is to send a JSON response called by AJAX. The thing is I cant NEVER find how to generate the token. I have tried

Tools::getAdminTokenLite('whatever');

with every possible thing (AdminModules, AdminModulesManage, ModuleController, etc etc etc) and I never get the same token as I see in the admin module list page and I can't find how to get it even from my back office admin module. The token itself doesn't even lpooks the same : I get tokens like ..8ee59a385ba5225cc52b.. with the Tools::getAdminTokenLite() method and the token in http://...../adminfolder/index.php/improve/modules/manage looks like LettERSOnLYWithCaps-a_CapsLowAnd1234_CAPSAND123.

The only place I can find this token is in $_SESSION as a csrf_token, but as it appears in links of admin menu tab (when you click on "modules" tab), its taken from somewhere, but where ?

Could you tell me how to get this token that I can use it to reach my endpoint from ajax please ?

Edited by Bruno G (see edit history)
Link to comment
Share on other sites

  • 1 year later...
  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...