def _cache_auth_token(self, token_obj):
        """
        Cache auth token in the config directory.

        :param token_obj: Token object.
        :type token_obj: ``object``
        """
        if not os.path.isdir(ST2_CONFIG_DIRECTORY):
            os.makedirs(ST2_CONFIG_DIRECTORY, mode=0o2770)
            # os.makedirs straight up ignores the setgid bit, so we have to set
            # it manually
            os.chmod(ST2_CONFIG_DIRECTORY, 0o2770)

        username = token_obj.user
        cached_token_path = self._get_cached_token_path_for_user(username=username)

        if not os.access(ST2_CONFIG_DIRECTORY, os.W_OK):
            # We don't have write access to the file with a cached token
            message = (
                'Unable to write token to "%s" (user %s doesn\'t have write '
                "access to the parent directory). Subsequent requests won't use a "
                "cached token meaning they may be slower."
                % (cached_token_path, os.getlogin())
            )
            self.LOG.warning(message)
            return None

        if os.path.isfile(cached_token_path) and not os.access(
            cached_token_path, os.W_OK
        ):
            # We don't have write access to the file with a cached token
            message = (
                'Unable to write token to "%s" (user %s doesn\'t have write '
                "access to this file). Subsequent requests won't use a "
                "cached token meaning they may be slower."
                % (cached_token_path, os.getlogin())
            )
            self.LOG.warning(message)
            return None

        token = token_obj.token
        expire_timestamp = parse_isotime(token_obj.expiry)
        expire_timestamp = calendar.timegm(expire_timestamp.timetuple())

        data = {}
        data["token"] = token
        data["expire_timestamp"] = expire_timestamp
        data = json.dumps(data)

        # Note: We explictly use fdopen instead of open + chmod to avoid a security issue.
        # open + chmod are two operations which means that during a short time frame (between
        # open and chmod) when file can potentially be read by other users if the default
        # permissions used during create allow that.
        fd = os.open(cached_token_path, os.O_WRONLY | os.O_CREAT, 0o660)
        with os.fdopen(fd, "w") as fp:
            fp.write(data)
        os.chmod(cached_token_path, 0o660)

        self.LOG.debug('Token has been cached in "%s"' % (cached_token_path))
        return True

        Cache auth token in the config directory.

        :param token_obj: Token object.
        :type token_obj: ``object``
        
st2client/st2client/base.py