Skip to content

Commit

Permalink
removing auth
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-dhanwant-yral committed Oct 7, 2024
1 parent a5ff74a commit 01e3c45
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,32 @@
"company": "gobazzinga",
}

class SignatureValidationInterceptor(grpc.ServerInterceptor):
def __init__(self):
def abort(ignored_request, context):
_LOGGER.warning("Aborting request due to invalid signature")
context.abort(grpc.StatusCode.UNAUTHENTICATED, "Invalid signature")
# class SignatureValidationInterceptor(grpc.ServerInterceptor):
# def __init__(self):
# def abort(ignored_request, context):
# _LOGGER.warning("Aborting request due to invalid signature")
# context.abort(grpc.StatusCode.UNAUTHENTICATED, "Invalid signature")

self._abort_handler = grpc.unary_unary_rpc_method_handler(abort)
# self._abort_handler = grpc.unary_unary_rpc_method_handler(abort)

def intercept_service(self, continuation, handler_call_details):
metadata_dict = dict(handler_call_details.invocation_metadata)
try:
token = metadata_dict[_AUTH_HEADER_KEY].split()[1]
payload = jwt.decode(
token,
_PUBLIC_KEY,
algorithms=["EdDSA"],
)
# def intercept_service(self, continuation, handler_call_details):
# metadata_dict = dict(handler_call_details.invocation_metadata)
# try:
# token = metadata_dict[_AUTH_HEADER_KEY].split()[1]
# payload = jwt.decode(
# token,
# _PUBLIC_KEY,
# algorithms=["EdDSA"],
# )

if payload == _JWT_PAYLOAD:
return continuation(handler_call_details)
else:
_LOGGER.warning(f"Received invalid payload: {payload}")
return self._abort_handler
except Exception as e:
_LOGGER.error(f"Exception occurred during token validation: {e}")
return self._abort_handler
# if payload == _JWT_PAYLOAD:
# return continuation(handler_call_details)
# else:
# _LOGGER.warning(f"Received invalid payload: {payload}")
# return self._abort_handler
# except Exception as e:
# _LOGGER.error(f"Exception occurred during token validation: {e}")
# return self._abort_handler
class SearchServicer(search_rec_pb2_grpc.SearchServiceServicer):
def __init__(self):
self.search_agent = SearchAgent()
Expand Down Expand Up @@ -94,7 +94,7 @@ def _run_server():

server = grpc.server(
futures.ThreadPoolExecutor(max_workers=_THREAD_CONCURRENCY),
interceptors=(SignatureValidationInterceptor(),),
# interceptors=(SignatureValidationInterceptor(),),
options=options
)
search_rec_pb2_grpc.add_SearchServiceServicer_to_server(
Expand Down

0 comments on commit 01e3c45

Please sign in to comment.