def _get_cached_auth_token(self, client, username, password):
        """
        Retrieve cached auth token from the file in the config directory.

        :rtype: ``str``
        """
        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)

        cached_token_path = self._get_cached_token_path_for_user(username=username)

        if not os.access(ST2_CONFIG_DIRECTORY, os.R_OK):
            # We don't have read access to the file with a cached token
            message = (
                'Unable to retrieve cached token from "%s" (user %s doesn\'t have read '
                "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 not os.path.isfile(cached_token_path):
            return None

        if not os.access(cached_token_path, os.R_OK):
            # We don't have read access to the file with a cached token
            message = (
                'Unable to retrieve cached token from "%s" (user %s doesn\'t have read '
                "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

        # Safety check for too permissive permissions
        file_st_mode = oct(os.stat(cached_token_path).st_mode & 0o777)
        others_st_mode = int(file_st_mode[-1])

        if others_st_mode >= 2:
            # Every user has access to this file which is dangerous
            message = (
                'Permissions (%s) for cached token file "%s" are too permissive. Please '
                "restrict the permissions and make sure only your own user can read "
                "from or write to the file." % (file_st_mode, cached_token_path)
            )
            self.LOG.warning(message)

        with open(cached_token_path) as fp:
            data = fp.read()

        try:
            data = json.loads(data)

            token = data["token"]
            expire_timestamp = data["expire_timestamp"]
        except Exception as e:
            msg = (
                'File "%s" with cached token is corrupted or invalid (%s). Please delete '
                " this file" % (cached_token_path, six.text_type(e))
            )
            raise ValueError(msg)

        now = int(time.time())
        if (expire_timestamp - TOKEN_EXPIRATION_GRACE_PERIOD_SECONDS) < now:
            self.LOG.debug(
                'Cached token from file "%s" has expired' % (cached_token_path)
            )
            # Token has expired
            return None

        self.LOG.debug('Using cached token from file "%s"' % (cached_token_path))
        return token

        Retrieve cached auth token from the file in the config directory.

        :rtype: ``str``
        
st2client/st2client/base.py