'Asks an identity server for a third party invite.
Args:
id_server (str): hostname + optional port for the identity server.
medium (str): The literal string "email".
address (str): The third party address being invited.
room_id (str): The ID of the room to which the user is invited.
inviter_user_id (str): The user ID of the inviter.
room_alias (str): An alias for the room, for cosmetic notifications.
room_avatar_url (str): The URL of the room\'s avatar, for cosmetic
notifications.
room_join_rules (str): The join rules of the email (e.g. "public").
room_name (str): The m.room.name of the room.
inviter_display_name (str): The current display name of the
inviter.
inviter_avatar_url (str): The URL of the inviter\'s avatar.
Returns:
A deferred tuple containing:
token (str): The token which must be signed to prove authenticity.
public_keys ([{"public_key": str, "key_validity_url": str}]):
public_key is a base64-encoded ed25519 public key.
fallback_public_key: One element from public_keys.
display_name (str): A user-friendly name to represent the invited
user.'

@defer.inlineCallbacks
def _ask_id_server_for_third_party_invite(self, id_server, medium, address, room_id, inviter_user_id, room_alias, room_avatar_url, room_join_rules, room_name, inviter_display_name, inviter_avatar_url):

    is_url = ('%s%s/_matrix/identity/api/v1/store-invite' % (id_server_scheme, id_server))
    invite_config = {'medium': medium, 'address': address, 'room_id': room_id, 'room_alias': room_alias, 'room_avatar_url': room_avatar_url, 'room_join_rules': room_join_rules, 'room_name': room_name, 'sender': inviter_user_id, 'sender_display_name': inviter_display_name, 'sender_avatar_url': inviter_avatar_url}
    if self.hs.config.invite_3pid_guest:
        registration_handler = self.hs.get_handlers().registration_handler
        guest_access_token = (yield registration_handler.guest_access_token_for(medium=medium, address=address, inviter_user_id=inviter_user_id))
        guest_user_info = (yield self.hs.get_auth().get_user_by_access_token(guest_access_token))
        invite_config.update({'guest_access_token': guest_access_token, 'guest_user_id': guest_user_info['user'].to_string()})
    data = (yield self.hs.get_simple_http_client().post_urlencoded_get_json(is_url, invite_config))
    token = data['token']
    public_keys = data.get('public_keys', [])
    if ('public_key' in data):
        fallback_public_key = {'public_key': data['public_key'], 'key_validity_url': ('%s%s/_matrix/identity/api/v1/pubkey/isvalid' % (id_server_scheme, id_server))}
    else:
        fallback_public_key = public_keys[0]
    if (not public_keys):
        public_keys.append(fallback_public_key)
    display_name = data['display_name']
    defer.returnValue((token, public_keys, fallback_public_key, display_name))
