Unable to access connectParams on request
jcunhafonte opened this issue · comments
José Cunha Fonte commented
- GraphQL AioWS version:
0.3.0 - Python version:
3.6.6
Description
When implementing this configuration https://www.apollographql.com/docs/angular/features/subscriptions.html#authentication I could not access connectionParams property on async def subscriptions(request):
Jessamyn Hodge commented
The above looks like a generic request handler for ws. Any authentication details should come over via your connection context, which you can then validate via the on_start / payload.
I did something like below
class CtxMonkeyPatch(AiohttpConnectionContext):
def __init__(self, ws, request_context):
super().__init__(ws, request_context)
self.logger = get_logger('ws_conn_ctx')
self.token = None
async def on_connect(self, payload):
if payload.get('context') is not None:
params = payload.get('context')
if params.get('access') is not None:
self.token = params.get('access')
async def on_start(self):
if self.token is not None:
try:
_user, _system = handle_token(self.token)
if _user is not None:
self.request_context['user'] = _user.get('user')
except Exception as e:
self.logger.error(e)
raise e
Chris Beaven commented
Should be fixed now in master