def get_groups_for_domain(service, domain):
    """
    Get all groups for a specified domain via Google API.

    :param service: Authenticated directory service object
    :param domain: The domain for groups
    :return: List of all groups
    """
    results = service.groups().list(domain=domain, maxResults=500).execute()

    groups = results.get('groups', [])

    while 'nextPageToken' in results:
        results = service.groups().list(domain=domain, maxResults=500,
                                        pageToken=results['nextPageToken']).execute()

        groups += results.get('groups', [])

    return groups