'Validate access token and get user_id from it
Args:
token (str): The access token to get the user by.
rights (str): The operation being performed; the access token must
allow this.
Returns:
dict : dict that includes the user and the ID of their access token.
Raises:
AuthError if no user by that token exists or the token is invalid.'

@defer.inlineCallbacks
def get_user_by_access_token(self, token, rights='access'):

    try:
        (user_id, guest) = self._parse_and_validate_macaroon(token, rights)
    except _InvalidMacaroonException:
        r = (yield self._look_up_user_by_access_token(token))
        defer.returnValue(r)
    try:
        user = UserID.from_string(user_id)
        if guest:
            stored_user = (yield self.store.get_user_by_id(user_id))
            if (not stored_user):
                raise AuthError(self.TOKEN_NOT_FOUND_HTTP_STATUS, ('Unknown    user_id    %s' % user_id), errcode=Codes.UNKNOWN_TOKEN)
            if (not stored_user['is_guest']):
                raise AuthError(self.TOKEN_NOT_FOUND_HTTP_STATUS, 'Guest    access    token    used    for    regular    user', errcode=Codes.UNKNOWN_TOKEN)
            ret = {'user': user, 'is_guest': True, 'token_id': None, 'device_id': GUEST_DEVICE_ID}
        elif (rights == 'delete_pusher'):
            ret = {'user': user, 'is_guest': False, 'token_id': None, 'device_id': None}
        else:
            ret = (yield self._look_up_user_by_access_token(token))
            if (ret['user'] != user):
                logger.error('Macaroon    user    (%s)    !=    DB    user    (%s)', user, ret['user'])
                raise AuthError(self.TOKEN_NOT_FOUND_HTTP_STATUS, 'User    mismatch    in    macaroon', errcode=Codes.UNKNOWN_TOKEN)
        defer.returnValue(ret)
    except (pymacaroons.exceptions.MacaroonException, TypeError, ValueError):
        raise AuthError(self.TOKEN_NOT_FOUND_HTTP_STATUS, 'Invalid    macaroon    passed.', errcode=Codes.UNKNOWN_TOKEN)
