MCPcopy Create free account
hub / github.com/apache/arrow / TokenServerAuthHandler

Class TokenServerAuthHandler

python/pyarrow/tests/test_flight.py:575–595  ·  view source on GitHub ↗

An example implementation of authentication via handshake.

Source from the content-addressed store, hash-verified

573
574
575class TokenServerAuthHandler(ServerAuthHandler):
576 """An example implementation of authentication via handshake."""
577
578 def __init__(self, creds):
579 super().__init__()
580 self.creds = creds
581
582 def authenticate(self, outgoing, incoming):
583 username = incoming.read()
584 password = incoming.read()
585 if username in self.creds and self.creds[username] == password:
586 outgoing.write(base64.b64encode(b'secret:' + username))
587 else:
588 raise flight.FlightUnauthenticatedError(
589 "invalid username/password")
590
591 def is_valid(self, token):
592 token = base64.b64decode(token)
593 if not token.startswith(b'secret:'):
594 raise flight.FlightUnauthenticatedError("invalid token")
595 return token[7:]
596
597
598class TokenClientAuthHandler(ClientAuthHandler):

Callers 1

test_flight.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected