def authenticate(self, force=False):
        reqbody = json.dumps({'auth': {
            'passwordCredentials': {
                'username': self.user_id,
                'password': self.key
            },
            'tenantId': self._ex_tenant_id
        }})
        resp = self.request('/tokens', data=reqbody, headers={},
                            method='POST')

        if resp.status == httplib.UNAUTHORIZED:
            # HTTP UNAUTHORIZED (401): auth failed
            raise InvalidCredsError()
        elif resp.status != httplib.OK:
            body = 'code: %s body:%s' % (resp.status, resp.body)
            raise MalformedResponseError('Malformed response', body=body,
                                         driver=self.driver)
        else:
            try:
                body = json.loads(resp.body)
            except Exception:
                e = sys.exc_info()[1]
                raise MalformedResponseError('Failed to parse JSON', e)

            try:
                expires = body['access']['token']['expires']

                self.auth_token = body['access']['token']['id']
                self.auth_token_expires = parse_date(expires)
                self.urls = body['access']['serviceCatalog']
                self.auth_user_info = None
            except __HOLE__:
                e = sys.exc_info()[1]
                raise MalformedResponseError('Auth JSON response is \
                                             missing required elements', e)

        return self
dataset/ETHPy150Open apache/libcloud/libcloud/compute/drivers/cloudwatt.py/CloudwattAuthConnection.authenticate