Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'status': 'ok',
'session_id': 'sess_123',
# this should be ignored
'foo': 'bar',
})
await session.on_client_event({
'event': 'auth',
'method': 'ticket',
'ticket': 'invalid_ticket',
})
assert client.log.pop() == {
'status': 'error',
'event': 'auth',
'error': c.ERR_AUTH_FAILED,
}
assert session.auth_info == {}
await session.on_client_event({
'event': 'auth',
'method': 'ticket',
'ticket': 'valid_ticket',
})
assert client.log.pop() == {
'status': 'ok',
'event': 'auth',
}
assert session.auth_info == {
'session_id': 'sess_123',
raise EventError(c.ERR_AUTH_UNSUPPORTED)
# The only supported method.
assert self.method == 'ticket'
auth_method_config = self.auth_config[self.method]
ticket = self.data.get('ticket')
if not ticket:
raise EventError(c.ERR_NEEDS_TICKET)
auth_url = auth_method_config['validation_url']
auth_fields = auth_method_config['auth_fields']
result = await http_post(self.shark, auth_url, {'ticket': ticket})
if result.get('status') != 'ok':
raise EventError(result.get('error', c.ERR_AUTH_FAILED))
auth_info = {field: result[field] for field in auth_fields}
self.session.auth_info = auth_info
self.session.log.debug('auth info', auth_info=auth_info)
await self.send_ok()
return True