'Get a registered user\'s ID.
Args:
request - An HTTP request with an access_token query parameter.
Returns:
defer.Deferred: resolves to a ``synapse.types.Requester`` object
Raises:
AuthError if no user by that token exists or the token is invalid.'

@defer.inlineCallbacks
def get_user_by_req(self, request, allow_guest=False, rights='access'):

    try:
        (user_id, app_service) = (yield self._get_appservice_user_id(request))
        if user_id:
            request.authenticated_entity = user_id
            defer.returnValue(synapse.types.create_requester(user_id, app_service=app_service))
        access_token = get_access_token_from_request(request, self.TOKEN_NOT_FOUND_HTTP_STATUS)
        user_info = (yield self.get_user_by_access_token(access_token, rights))
        user = user_info['user']
        token_id = user_info['token_id']
        is_guest = user_info['is_guest']
        device_id = user_info.get('device_id')
        ip_addr = self.hs.get_ip_from_request(request)
        user_agent = request.requestHeaders.getRawHeaders('User-Agent', default=[''])[0]
        if (user and access_token and ip_addr):
            self.store.insert_client_ip(user=user, access_token=access_token, ip=ip_addr, user_agent=user_agent, device_id=device_id)
        if (is_guest and (not allow_guest)):
            raise AuthError(403, 'Guest    access    not    allowed', errcode=Codes.GUEST_ACCESS_FORBIDDEN)
        request.authenticated_entity = user.to_string()
        defer.returnValue(synapse.types.create_requester(user, token_id, is_guest, device_id, app_service=app_service))
    except KeyError:
        raise AuthError(self.TOKEN_NOT_FOUND_HTTP_STATUS, 'Missing    access    token.', errcode=Codes.MISSING_TOKEN)
