Skip to content
Snippets Groups Projects
Select Git revision
  • 611e8fceaed1cadc16faba04f446bc790261b217
  • master default protected
  • feat/npm-publish
  • feat/demo-deploy
  • change-demo-deploy
  • remove-smoke
  • feat/acceptance-tests
  • feature/deploy-composer.json
  • feature/mysql-bin-logs
  • skip-codecept-for-libs
  • include-composer-json
  • exclude-wp-assets
  • update_codecept_image
  • fix/silenced-copy
  • remove-free-translations
  • codeception-with-optional-step
  • improve-parallelization
  • linter-exit
  • change-images
  • fix/linter
  • globally-raise-mem-limit
  • no-symlink2
22 results

prepare.yml

Blame
  • JWTSaasToken.php 1.23 KiB
    <?php
    
    namespace WPDesk\ApiClient\Authentication;
    
    class JWTSaasToken implements Token
    {
        const SHOP_ID_PARAM = 'shop';
    
        const ROLE_PARAM = 'ROLE_SHOP';
    
    
        /** @var JWTToken */
        private $token;
    
        /**
         * JWTToken constructor.
         * @param string $token
         */
        public function __construct(JWTToken $token)
        {
            $this->token = $token;
        }
    
        public function getAuthString()
        {
            return $this->token->getAuthString();
        }
    
        public function isExpired()
        {
            return $this->token->isExpired();
        }
    
        public function isSignatureValid()
        {
            return $this->token->isSignatureValid();
        }
    
        public function __toString()
        {
            return $this->token->__toString();
        }
    
        /**
         * If there is shop id in the token
         *
         * @return bool
         */
        public function hasShopId()
        {
            $info = $this->token->getDecodedPublicTokenInfo();
            return !empty($info[self::SHOP_ID_PARAM]) && in_array(self::ROLE_PARAM, $info['roles']);
        }
    
        /**
         * Get shop id from token
         *
         * @return int
         */
        public function getShopId()
        {
            $info = $this->token->getDecodedPublicTokenInfo();
            return (int)$info[self::SHOP_ID_PARAM];
        }
    
    }