Skip to content
Snippets Groups Projects
Select Git revision
  • a3c95609fcd7d201567113b2d1d2f44085e3fabf
  • main default protected
  • v0.10
  • 0.10.6
  • 0.10.5
  • 0.10.4
  • 0.10.3
  • 0.10.2
  • 0.10.1
  • 0.10.0
  • 0.9.1
  • 0.9.0
12 results

ConfigurationBindingLoader.php

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];
        }
    
    }