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

Class TokenServerAuthHandler

python/pyarrow/tests/test_flight.py:577–597  ·  view source on GitHub ↗

An example implementation of authentication via handshake.

Source from the content-addressed store, hash-verified

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

Callers 1

test_flight.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected