diff --git a/fabapi/connect.py b/fabapi/connect.py index 079df6c..c77d903 100644 --- a/fabapi/connect.py +++ b/fabapi/connect.py @@ -38,20 +38,17 @@ async def connect(host, port, user, pw): # Start TwoPartyClient using TwoWayPipe (takes no arguments in this mode) client = capnp.TwoPartyClient() - cap = client.bootstrap().cast_as(connection_capnp.Bootstrap) # Assemble reader and writer tasks, run in the background coroutines = [myreader(client, reader), mywriter(client, writer)] asyncio.gather(*coroutines, return_exceptions=True) - auth = cap.authenticationSystem().authenticationSystem - req = auth.start_request() - req.request.mechanism = "PLAIN" - req.request.initialResponse.initial = "\0" + user + "\0" + pw - rep_prom = req.send() - response = await rep_prom.a_wait() - if response.response.outcome.result == "successful": - return cap + boot = client.bootstrap().cast_as(connection_capnp.Bootstrap) + auth = await boot.createSession("PLAIN").a_wait() + p = "\0" + user + "\0" + pw + response = await auth.authentication.step(p).a_wait() + if response.which() == 'successful': + return response.successful.session else: - print("Auth failed") + print("Authentication failed!") return None diff --git a/test.py b/test.py index ac27c8d..1ded36c 100644 --- a/test.py +++ b/test.py @@ -3,12 +3,8 @@ import fabapi async def main(): - boot = await fabapi.connect("localhost", 59661, "Testuser", "secret") - if boot: - ms = await boot.machineSystem().a_wait() - info = await ms.machineSystem.info().a_wait() - ma = await info.info.getMachineURN("urn:fabaccess:resource:Another").a_wait() - print(ma.machine) + session = await fabapi.connect("localhost", 59661, "Testuser", "secret") + print(session) if __name__ == "__main__": loop = asyncio.get_event_loop()