import requests


def list_owned_scenes(user_id, jwt):
    """
    List all owned scenes
    Args:
        user_id: rfclient.owner
        jwt: rfclient.api.api_token
    Returns:
        list of scenes
    """
    def make_request(headers, page, page_size=1000):
        return requests.get(
            'https://{host}/api/scenes'.format(host=rf_host),
            headers=headers,
            params={
                'pageSize': page_size,
                'page': page,
                'owner': user_id
            }
        )
    headers = {'Authorization': jwt}
    rf_host = 'app.rasterfoundry.com'
    page = 0
    resp = make_request(headers, page)
    resp.raise_for_status()
    js = resp.json()
    scenes = js['results']
    has_next = js['hasNext']

    while has_next:
        page += 1
        resp = make_request(headers, page)
        resp.raise_for_status()
        js = resp.json()
        scenes.extend(js['results'])
        has_next = js['hasNext']

    return scenes