Discharge token for a user.

        Raise a ServerError if an error occurs in the request process.

        @param username The logged in user.
        @return The resulting base64 encoded discharged token.

def discharge_token(self, username):
        """Discharge token for a user.

        Raise a ServerError if an error occurs in the request process.

        @param username The logged in user.
        @return The resulting base64 encoded discharged token.
        """
        url = '{}discharge-token-for-user?username={}'.format(
            self.url, quote(username))
        logging.debug('Sending identity info to {}'.format(url))
        response = make_request(url, method='GET', timeout=self.timeout)
        try:
            macaroon = response['DischargeToken']
            json_macaroon = json.dumps(macaroon)
        except (KeyError, UnicodeDecodeError) as err:
            raise InvalidMacaroon(
                'Invalid macaroon from discharger: {}'.format(err.message))
        return base64.urlsafe_b64encode("[{}]".format(
            json_macaroon).encode('utf-8'))