async def METHOD_NAME(
    backend: BackendApp, handshake: ServerHandshake
) -> Tuple[BaseClientContext | None, bytes, dict[str, object] | None]:
    organization_id = cast(OrganizationID, handshake.answer_data["organization_id"])
    invitation_type = cast(InvitationType, handshake.answer_data["invitation_type"])
    token = handshake.answer_data["token"]
    def _make_error_infos(reason: str) -> dict[str, object]:
        return {
            "reason": reason,
            "handshake_type": HandshakeType.INVITED,
            "organization_id": organization_id,
            "invitation_type": invitation_type,
            "token": token,
        }
    try:
        organization = await backend.organization.get(organization_id)
    except OrganizationNotFoundError:
        result_req = handshake.build_bad_identity_result_req()
        return None, result_req, _make_error_infos("Bad organization")
    if organization.is_expired:
        result_req = handshake.build_organization_expired_result_req()
        return None, result_req, _make_error_infos("Expired organization")
    try:
        invitation = await backend.invite.info(
            organization_id, token=cast(InvitationToken, handshake.answer_data["token"])
        )
    except InvitationAlreadyDeletedError:
        result_req = handshake.build_bad_identity_result_req(
            help="Invalid handshake: Invitation already deleted"
        )
        return None, result_req, _make_error_infos("Bad invitation")
    except InvitationNotFoundError:
        result_req = handshake.build_bad_identity_result_req(
            help="Invalid handshake: Invitation not found"
        )
        return None, result_req, _make_error_infos("Bad invitation")
    except InvitationError:
        result_req = handshake.build_bad_identity_result_req()
        return None, result_req, _make_error_infos("Bad invitation")
    expected_invitation_type = (
        UserInvitation
        if handshake.answer_data["invitation_type"] == InvitationType.USER
        else DeviceInvitation
    )
    if not isinstance(invitation, expected_invitation_type):
        result_req = handshake.build_bad_identity_result_req()
        return None, result_req, _make_error_infos("Bad invitation")
    context = InvitedClientContext(
        api_version=handshake.backend_api_version,
        client_api_version=handshake.client_api_version,
        organization_id=organization_id,
        invitation=invitation,
    )
    result_req = handshake.build_result_req()
    return context, result_req, None