HEX
Server: Apache
System: Linux efa57bbe-abb1-400d-2985-3b056fbc2701.secureserver.net 6.1.147-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 24 12:33:32 EDT 2025 x86_64
User: root (0)
PHP: 8.0.30.4
Disabled: NONE
Upload Files
File: //var/chroot/var/www/wp-content/mu-plugins/vendor/godaddy/mwc-core/src/Auth/JWT/TokenDecoder.php
<?php

namespace GoDaddy\WordPress\MWC\Core\Auth\JWT;

use DomainException;
use Exception;
use GoDaddy\WordPress\MWC\Common\Auth\JWT\Contracts\JwtDecoderContract;
use GoDaddy\WordPress\MWC\Common\Exceptions\JwtDecoderException;
use GoDaddy\WordPress\MWC\Core\Vendor\Firebase\JWT\JWK;
use GoDaddy\WordPress\MWC\Core\Vendor\Firebase\JWT\JWT;
use InvalidArgumentException;
use stdClass;
use UnexpectedValueException;

/**
 * JWT Token Decoder.
 */
class TokenDecoder implements JwtDecoderContract
{
    /** @var mixed[] */
    protected array $keySet;

    /** @var string */
    protected string $defaultAlgorithm = 'RS256';

    /**
     * Sets the keyset.
     *
     * @param mixed[] $value
     * @return $this
     */
    public function setKeySet(array $value) : JwtDecoderContract
    {
        $this->keySet = $value;

        return $this;
    }

    /**
     * Sets the default algorithm that'll be used to decode the JWT if the key (JWK) doesn't specify an alg value.
     *
     * @param string $value
     * @return $this
     */
    public function setDefaultAlgorithm(string $value) : JwtDecoderContract
    {
        $this->defaultAlgorithm = $value;

        return $this;
    }

    /**
     * Decodes the token.
     *
     * @param string $token
     *
     * @return stdClass
     * @throws JwtDecoderException
     */
    public function decode(string $token) : stdclass
    {
        try {
            return JWT::decode($token, JWK::parseKeySet($this->keySet, $this->defaultAlgorithm));
        } catch(DomainException|InvalidArgumentException|UnexpectedValueException|Exception $exception) {
            throw new JwtDecoderException($exception->getMessage(), $exception);
        }
    }
}