def is_valid(self, token: bytes): """Check if the supplied token is valid.""" if token == "" or token is None: raise fl.FlightUnauthenticatedError("invalid token") if not self._app.get_api_keys().has_api_key(token.decode("UTF-8")): raise fl.FlightUnauthenticatedError("invalid token") return token
def is_valid(self, token): logging.info('HttpBasicServerAuthHandler: is_valid()') if not token: raise flight.FlightUnauthenticatedError("token not provided") if token.decode() not in self.creds: raise flight.FlightUnauthenticatedError("unknown user") return token
def authenticate(self, outgoing, incoming): buf = incoming.read() auth = flight.BasicAuth.deserialize(buf) if auth.username not in self.creds: raise flight.FlightUnauthenticatedError("unknown user") if self.creds[auth.username] != auth.password: raise flight.FlightUnauthenticatedError("wrong password") outgoing.write(tobytes(auth.username))
def authenticate(self, outgoing, incoming): buf = incoming.read() auth = flight.BasicAuth.deserialize(buf) logging.info('HttpBasicServerAuthHandler: authenticate(). username: {}'.format(auth.username.decode())) if auth.username.decode() not in self.creds: raise flight.FlightUnauthenticatedError("unknown user") if self.creds[auth.username.decode()] != auth.password.decode(): raise flight.FlightUnauthenticatedError("wrong password") outgoing.write(auth.username)
def is_valid(self, token): if not token: raise flight.FlightUnauthenticatedError("token not provided") token = base64.b64decode(token) username, password = token.split(b':') if username not in self.creds: raise flight.FlightUnauthenticatedError("unknown user") if self.creds[username] != password: raise flight.FlightUnauthenticatedError("wrong password") return username
def authenticate(self, outgoing, incoming): buf = incoming.read() auth = flight.BasicAuth.deserialize(buf) logger.info('basic authentication', extra={'username': auth.username.decode()}) if auth.username.decode() not in self.creds: raise flight.FlightUnauthenticatedError("unknown user") if self.creds[auth.username.decode()] != auth.password.decode(): raise flight.FlightUnauthenticatedError("wrong password") outgoing.write(auth.username)
def authenticate(self, outgoing, incoming): """Check the authentication.""" buf = incoming.read() auth = fl.BasicAuth.deserialize(buf) if auth.username is None: raise fl.FlightUnauthenticatedError("invalid username") if auth.password is None: raise fl.FlightUnauthenticatedError("invalid password") if not self._app.get_api_keys().is_valid( auth.username.decode("UTF-8"), auth.password.decode("UTF-8")): raise fl.FlightUnauthenticatedError("invalid token") outgoing.write(auth.username)
def start_call(self, info, headers): if info.method == flight.FlightMethod.LIST_ACTIONS: # No auth needed return token = headers.get("x-auth-token") if not token: raise flight.FlightUnauthenticatedError("No token") token = token[0] if token != "password": raise flight.FlightUnauthenticatedError("Invalid token") return HeaderServerMiddleware(token)
def authenticate(self, outgoing, incoming): username = incoming.read() password = incoming.read() if username in self.creds and self.creds[username] == password: outgoing.write(base64.b64encode(b'secret:' + username)) else: raise flight.FlightUnauthenticatedError( "invalid username/password")
def do_action(self, context, action): if action.type == "internal": raise flight.FlightInternalError("foo") elif action.type == "timedout": raise flight.FlightTimedOutError("foo") elif action.type == "cancel": raise flight.FlightCancelledError("foo") elif action.type == "unauthenticated": raise flight.FlightUnauthenticatedError("foo") elif action.type == "unauthorized": raise flight.FlightUnauthorizedError("foo") raise NotImplementedError
def do_action(self, context, action): if action.type == "internal": raise flight.FlightInternalError("foo") elif action.type == "timedout": raise flight.FlightTimedOutError("foo") elif action.type == "cancel": raise flight.FlightCancelledError("foo") elif action.type == "unauthenticated": raise flight.FlightUnauthenticatedError("foo") elif action.type == "unauthorized": raise flight.FlightUnauthorizedError("foo") elif action.type == "protobuf": err_msg = b'this is an error message' raise flight.FlightUnauthorizedError("foo", err_msg) raise NotImplementedError
def is_valid(self, token): token = base64.b64decode(token) if not token.startswith(b'secret:'): raise flight.FlightUnauthenticatedError("invalid token") return token[7:]
def is_valid(self, token): if not token: raise flight.FlightUnauthenticatedError("token not provided") if token not in self.creds: raise flight.FlightUnauthenticatedError("unknown user") return token