public static function validateToken($tokenString)
    {
        $tokens = ApiToken::find(new AndGroup(
            [
                new Equals("Token", $tokenString),
                new GreaterThan("Expires", "now", true)
            ]
        ));

        if (count($tokens) != 1) {
            throw new TokenInvalidException();
        }

        /** @var ApiToken $token */
        $token = $tokens[0];
        $settings = ApiSettings::singleton();
        if ($settings->extendTokenExpirationOnUse) {
            $token->Expires = $settings->tokenExpiration;
            $token->save();
        }

        return $token->AuthenticatedUser;
    }