-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathgrpc.py
More file actions
33 lines (25 loc) · 1.01 KB
/
grpc.py
File metadata and controls
33 lines (25 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import asyncio
import logging
import grpc
from feast.permissions.auth.auth_manager import (
get_auth_manager,
)
from feast.permissions.security_manager import get_security_manager
logger = logging.getLogger(__name__)
class AuthInterceptor(grpc.ServerInterceptor):
def intercept_service(self, continuation, handler_call_details):
sm = get_security_manager()
if sm is not None:
auth_manager = get_auth_manager()
access_token = auth_manager.token_extractor.extract_access_token(
metadata=dict(handler_call_details.invocation_metadata)
)
logger.debug(
f"Fetching user details for token of length: {len(access_token)}"
)
current_user = asyncio.run(
auth_manager.token_parser.user_details_from_access_token(access_token)
)
logger.debug(f"User is: {current_user}")
sm.set_current_user(current_user)
return continuation(handler_call_details)