/ps_accounts

PrestaShop Accounts module

Primary LanguagePHPOpen Software License 3.0OSL-3.0

PrestaShop Account

Source Code Latest Version Software License Build Status

The module ps_accounts is the interface between your module and PrestaShop's services. It manages:

  • Shop association and dissociation processes.
  • Maintain secure communication between shop and Prestashop services.
  • Synchronize basic informations about the shops (Shop Urls).

Installation

If you need to install and test the module, you can download the desired zip here.

Compatibility Matrix

We aims to follow partially the Prestashop compatibility charts

ps_accounts version Prestashop Version PHP Version
7.x (unified) >=1.6 && <9.x PHP 5.6 - 8
6.x >=8.0.0 PHP 7.2 - 8
5.x >=1.6 && <8.0.0 PHP 5.6 - 7.4

Integration along with your Prestashop module

If you are integrating a module, you should have a look on the PrestaShop Integration Framework Documentation.

APIs

Here are listed Open APIs provided by this module:

HTTP Verb Controller Method Payload Description
GET AdminAjaxPsAccounts getOrRefreshAccessToken { token: "<access_token>" } Return a token provided by Prestashop OpenId Connect Provider when the user has been authenticated by this provider

Example: I want to get the authenticated user token in order make action on his behalf. The request would be GET https://<shop-admin-url>/index.php?controller=AdminAjaxPsAccounts&action=getOrRefreshAccessToken&ajax=true&token=<token> where token is a Prestashop Admin token.

Custom hooks

Here are listed custom hooks provided with this module:

Hook name Payload Description
actionShopAccountLinkAfter shopId, shopUuid Triggered after link has been acknowledged by shop
actionShopAccountUnlinkAfter shopId, shopUuid Triggered after unlink has been acknowledged by shop
actionShopAccessTokenRefreshAfter token Trigger after OAuth access token has been refreshed

JWT

JSON Web Token RFC (JWT).

All the tokens exposed follow the OpenId Connect Token and Access Tokens Specs.

This modules manages the following tokens:

JWT Name Status Description
Shop Token (legacy) Deprecated 7.x This token can be used to act as the shop. It should be used only for machine to machine communication without user interaction
Shop Owner Token (legacy) Deprecated 7.X This token is created for the owner who associate the shop.
Authenticated User Token Introduced 6.x ex: Backend Login with PrestaShop SSO
OAuth Shop Access Token Introduced 7.X For machine to machine calls. (also used to keep up to date legacy Shop and Owner tokens).

Development

This module has three parts:

  • PS Accounts module
    • This module must be installed.
    • It's your interface between your module and PrestaShop Accounts service.
  • PS Accounts Installer (Composer Library)
    • This library's role is here to compensate a lack of security between modules dependencies. If PS Accounts is removed while your module is still installed: it causes a crash of the PrestaShop module's page/feature.
    • This library is here to install automatically PS Accounts if it's missing.
    • It's your interface between your module and PrestaShop Accounts module
    • You should never require directly PrestaShop\Module\PsAccounts namespace classes
  • PrestaShop Accounts Vue Components
    • It's the front-end component you need to integrate into your module's configuration page.

How to start working with PS Accounts as a PSx or Community Service developer?

Testing

This repository has a Makefile. Just run for running phpunit make phpunit and make phpstan.

JWT

We use JWTs for 2 types of account: the user account and the shop account. What we're identifying when we link a PrestaShop shop is a shop. A shop belongs to 1 owner (user).

There are 2 Firebase projects:

  • prestashop-newsso-production is the Firebase Authentication project we're using to authenticate users (prestashop-newsso-staging) for staging environment
  • prestashop-ready-prod is the Firebase Authentication project we're using to authenticate shops (psessentials-integration) for integration environment

How to get upd to date (legacy) JWT Tokens

use PrestaShop\PsAccountsInstaller\Installer\Installer;
use PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts;

define('MIN_PS_ACCOUNTS_VERSION', '4.0.0');

$facade = new PsAccounts(new Installer(MIN_PS_ACCOUNTS_VERSION));

// Get or refresh shop token
$shopToken = $facade->getPsAccountsService()->getOrRefreshToken();

// Get or refresh shop owner token 
$ownerToken = $facade->getPsAccountsService()->getUserToken();

see: PrestaShop Accounts Installer for more details on how to setup Installer.

Breaking Changes

Removal of the environment variables

This module don't use a .env file as a configuration file. We are now using YAML files with a Symfony service container to configure services and their injected dependencies as well as configuration parameters. You can copy and paste the config.yml.dist to config.yml but you MUST NOT COMMIT THIS FILE

Composer dependency prestashop_accounts_auth deprecated

This library will be deprecated and no longer needed. Please remove it from your module's dependencies.

New composer dependency prestashop-accounts-installer

Do not directly import PrestaShop Accounts classes

If you need to call PrestaShop Accounts public classes's methods, you need to use the service container.

see: PrestaShop Accounts Installer

PS EventBus is no longer installed for 1.6.x versions

The ps_eventbus module is no longer installed automatically for Prestashop version <1.7.

APIs removal

Those API has been removed:

  • /carts
  • /categories
  • /deletedObjects
  • /googleTaxonomies
  • /apiHealthCheck
  • /info
  • /modules
  • /orders
  • /products
  • /themes