def discharge(self, username, macaroon):
        """Discharge the macarooon for the identity.

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

        @param username The logged in user.
        @param macaroon The macaroon returned from the charm store.
        @return The resulting base64 encoded macaroon.
        @raises ServerError when making request to the discharge endpoint
        InvalidMacaroon when the macaroon passedin or discharged is invalid
        """
        caveats = macaroon.third_party_caveats()
        if len(caveats) != 1:
            raise InvalidMacaroon(
                'Invalid number of third party caveats (1 != {})'
                ''.format(len(caveats)))
        url = '{}discharger/discharge?discharge-for-user={}&id={}'.format(
            self.url, quote(username), caveats[0][1])
        logging.debug('Sending identity info to {}'.format(url))
        logging.debug('data is {}'.format(caveats[0][1]))
        response = make_request(url, method='POST', timeout=self.timeout)
        try:
            macaroon = response['Macaroon']
            json_macaroon = json.dumps(macaroon)
        except (KeyError, UnicodeDecodeError) as err:
            raise InvalidMacaroon(
                'Invalid macaroon from discharger: {}'.format(err.message))

        return base64.urlsafe_b64encode(json_macaroon.encode('utf-8'))