Validate token and returns triplet containing sbas_id, record_id and subdef.

@param string|object $token
@return array
439693
public function validateToken($token)
    {
        if (is_string($token)) {
            $token = $this->decodeToken($token);
        }

        if (!isset($token->sdef) || !is_array($token->sdef) || count($token->sdef) !== 3) {
            throw new BadRequestHttpException('sdef should be a sub-definition identifier.');
        }
        list ($sbas_id, $record_id, $subdef) = $token->sdef;

        return array($sbas_id, $record_id, $subdef);
    }
254322
public static function getHeader(string $token, string $secret): array
    {
        $parser = self::parser($token, $secret);

        return $parser->validate()->parse()->getHeader();
    }
906483
protected function checkToken($token)
    {
        if (!$token) {
            return false;
        }

        $file = $this->pathForToken($token);
        $content = null;

        if (file_exists($file)) {
            $content = file_get_contents($file);
            unlink($file);
        }

        return $content === $token;
    }
15586
public static function decodeToken($token) {
        global $CFG;
        $plain = AesCtr::decrypt($token, $CFG->websocket_secret, 256) ;
        $pieces = explode('::', $plain);
        if ( count($pieces) != 4 ) return false;
        return $plain;
    }
196943
protected function findUserByToken(Token $token)
    {
        // retrieves the user ID from the token.
        $id = $token->getClaim('sub');

        // use the users provider to find the token subject (user)
        // but it's id (subject)
        return $this->provider->retrieveById($id);
    }
1125394
protected static function transform_token($record) {
        $notexportedstr = get_string('privacy:request:notexportedsecurity', 'core_webservice');
        return [
            'external_service' => $record->externalservicename,
            'token' => $notexportedstr,
            'private_token' => $record->privatetoken ? $notexportedstr : null,
            'ip_restriction' => $record->iprestriction,
            'valid_until' => $record->validuntil ? transform::datetime($record->validuntil) : null,
            'created_on' => transform::datetime($record->timecreated),
            'last_access' => $record->lastaccess ? transform::datetime($record->lastaccess) : null,
        ];
    }
975920
private function decodeToken(string $token): array
    {
        try {
            $decoded = JWT::decode(
                $token,
                $this->options["secret"],
                (array) $this->options["algorithm"]
            );
            return (array) $decoded;
        } catch (Exception $exception) {
            $this->log(LogLevel::WARNING, $exception->getMessage(), [$token]);
            throw $exception;
        }
    }
862702
public static function getSpaceFromToken($token) {
        $pieces = explode('::', $token);
        if ( count($pieces) != 4 ) return false;
        $space = implode('::', array_slice($pieces,0,2));
        return $space;
    }
1334115
protected function decrypt($token)
    {
        // Decrypt the token if there is an Encrypter instance
        if ($this->encrypter instanceof Encrypter) {
            $token = $this->encrypter->decrypt($token);
        }
        
        // Return the unserialized token
        return @unserialize($token);
    }
783474
public static function realTokenToArray($token)
    {
        $class = get_class($token);

        $tokenArray = array(
            'class' => $class,

            // 'extraParams' => $token->getExtraParams(),
        );

        if(get_class($token) === 'League\OAuth1\Client\Credentials\TokenCredentials' || is_subclass_of($token, '\League\OAuth1\Client\Credentials\TokenCredentials'))
        {
            // OAuth 1.0
            $tokenArray['identifier'] = $token->getIdentifier();
            $tokenArray['secret'] = $token->getSecret();
        }
        elseif(get_class($token) === 'League\OAuth2\Client\Token\AccessToken' || is_subclass_of($token, '\League\OAuth2\Client\Token\AccessToken'))
        {
            // OAuth 2.0
            $tokenArray['accessToken'] = $token->getToken();
            $tokenArray['refreshToken'] = $token->getRefreshToken();
            $tokenArray['endOfLife'] = $token->getExpires();
        }

        return $tokenArray;
    }
953570
public function getUserIdFromToken(string $token): string
    {
        if (!$this->isTokenValid($token)) {
            throw new \InvalidArgumentException('This token is invalid');
        }
        $tokenData = $this->decryptToken($token);

        return $tokenData['user_id'];
    }
536379
public function parse(Token $token)
    {
        $range = $this->buildRange($token);
        $references = [];
        $from = $range->getFrom();
        $to = $range->getTo();
        $step = $range->getStep();
        for ($currentIndex = $from; $currentIndex <= $to; $currentIndex += $step) {
            $fixtureId = str_replace($this->token, $currentIndex, $range->getName());
            $references[] = new FixtureReferenceValue($fixtureId);
        }

        return new ArrayValue($references);
    }
701444
protected static function _splitConditions($token)
    {
        $conditions = false;
        $position = strpos($token, '[');
        if ($position !== false) {
            $conditions = substr($token, $position);
            $token = substr($token, 0, $position);
        }

        return [$token, $conditions];
    }
1320319
private function resolveToken( $token )
    {
        $replaceString = "";
        $tokenParts = $this->tokenParts( $token );

        foreach ( $tokenParts as $tokenPart )
        {
            if ( $this->isTokenGroup( $tokenPart ) )
            {
                $groupTokenArray = $this->extractTokens( $this->groupLookupTable[$tokenPart] );
                $replaceString = $this->groupLookupTable[$tokenPart];

                foreach ( $groupTokenArray as $groupToken )
                {
                    $replaceString = str_replace( $groupToken, $this->resolveToken( $groupToken ), $replaceString );
                }
                // We want to stop after the first matching token part / identifier is found
                // <id1|id2> if id1 has a value, id2 will not be used.
                // In this case id1 or id1 is a token group.
                break;
            }
            else
            {
                if ( isset( $this->attributeArray[$tokenPart] ) && $this->attributeArray[$tokenPart] !== '' && $this->attributeArray[$tokenPart] !== false )
                {
                    $replaceString = $this->attributeArray[$tokenPart];
                    // We want to stop after the first matching token part / identifier is found
                    // <id1|id2> if id1 has a value, id2 will not be used.
                    break;
                }
            }
        }
        return $replaceString;
    }
6825
public static function isActivationTokenValid($token)
    {
        $expire = Podium::getInstance()->podiumConfig->get('activation_token_expire');
        if ($expire === null) {
            $expire = 3 * 24 * 60 * 60;
        }
        return static::isTokenValid($token, $expire);
    }
235512
public function filter($token)
    {
        // Apply replacements
        if ($this->tokenFrom) {
            $token = strtr($token, $this->tokenFrom, $this->tokenTo);
        }
        
        // If not case sensitive, convert to lowercase
        if (! $this->tokenCaseSensitive) {
            $token = strtolower($token);
        }
        
        // Filter out invalid chars
        $tokenLength   = strlen($token);
        $filteredToken = '';
        
        for ($tokenPos = 0; ($tokenPos < $tokenLength); $tokenPos++) {
            if (strpos($this->tokenChars, $token[$tokenPos]) !== false) {
                $filteredToken .= $token[$tokenPos];
            }
        }

        // Now check against the format for fixed chars
        $formatLength = strlen($this->tokenFormat);
        $tokenLength  = strlen($filteredToken);
        $tokenPos     = 0;
        $resultToken  = '';
        
        for ($formatPos = 0; ($formatPos < $formatLength) && ($tokenPos < $tokenLength); $formatPos++) {
            if ('\\' == $this->tokenFormat[$formatPos]) {
                $formatPos++;
                $resultToken .= $this->tokenFormat[$formatPos];

            } else {                
                $resultToken .= $filteredToken[$tokenPos];
                $tokenPos++;
            }
        }
        
        // Separate extra chars with a space and a questionmark
        if ($tokenPos < $tokenLength) {
            $resultToken .= ' ?' . substr($filteredToken, $tokenPos);
        }

        return $resultToken;
    }
756245
public static function findByEmailToken($token)
    {
        if (!static::isEmailTokenValid($token)) {
            return null;
        }
        return static::find()->where(['email_token' => $token, 'status' => self::STATUS_ACTIVE])->limit(1)->one();
    }