async def authenticate_with_macaroon(url, insecure=False):
    """Login via macaroons and generate and return new API keys."""
    executor = futures.ThreadPoolExecutor(max_workers=1)

    def get_token():
        client = httpbakery.Client()
        resp = client.request(
            'POST', '{}/account/?op=create_authorisation_token'.format(url),
            verify=not insecure)
        if resp.status_code == HTTPStatus.UNAUTHORIZED:
            # if the auteentication with Candid fails, an exception is raised
            # above so we don't get here
            raise MacaroonLoginNotSupported(
                'Macaroon authentication not supported')
        if resp.status_code != HTTPStatus.OK:
            raise LoginError('Login failed: {}'.format(resp.text))
        result = resp.json()
        return '{consumer_key}:{token_key}:{token_secret}'.format(**result)

    loop = asyncio.get_event_loop()
    return await loop.run_in_executor(executor, get_token)
async def authenticate_with_macaroon ( url , insecure = False ) : executor = futures . ThreadPoolExecutor ( max_workers = 1 ) def get_token ( ) : client = httpbakery . Client ( ) resp = client . request ( 'POST' , '{}/account/?op=create_authorisation_token' . format ( url ) , verify = not insecure ) if resp . status_code == HTTPStatus . UNAUTHORIZED : raise MacaroonLoginNotSupported ( 'Macaroon authentication not supported' ) if resp . status_code != HTTPStatus . OK : raise LoginError ( 'Login failed: {}' . format ( resp . text ) ) result = resp . json ( ) return '{consumer_key}:{token_key}:{token_secret}' . format ( ** result ) loop = asyncio . get_event_loop ( ) return await loop . run_in_executor ( executor , get_token )
Login via macaroons and generate and return new API keys.