<?php
/**
 * For the full copyright and license information, please view the
 * docs/licenses/LICENSE.txt file that was distributed with this source code.
 */

namespace PrestaShop\PrestaShop\Core\Security\OAuth2;

use Symfony\Component\HttpFoundation\Request;

/**
 * To integrate an authorization server you must implement this interface, the methods are bridges that call the authorization server
 * to ensure the access token is valid, if so it can return a representation of the user using the JwtTokenUser DTO.
 */
interface AuthorisationServerInterface
{
    /**
     * For each request received, the resource server loops through all the available servers implementing this interface
     * and uses this method to detect which one matches with the provided access token. Your implementation of each authorization
     * server must be able to recognize an access token it created, usually relying on the issuer saved in the metadata included
     * in the JWT token (no convention is forced, each authorization server may store this info differently as long as it can
     * recognize itself).
     *
     * @param Request $request
     *
     * @return bool
     */
    public function isTokenValid(Request $request): bool;

    /**
     * If the token is valid, the authorization server must return a representation of the user using the
     * JwtTokenUser DTO that contains:
     *  - userId: Usually, the Client ID
     *  - scopes: List of scopes authorized in the access token
     *  - issuer: An identifier for the authorization server that issued the token:
     *    - for external authorization servers: usually the address of the server
     *    - for our internal authorization server: null (it is the only allowed to use null as an issuer)
     *
     * @param Request $request
     *
     * @return JwtTokenUser|null
     */
    public function getJwtTokenUser(Request $request): ?JwtTokenUser;
}
