You would need to download the image to a temporary file, then pass that in to the various default avatar functions on the avatar model which will handle the resizing, copying and ultimate setting of the new avatar.
Effectively you can use XF code for everything except the initial bit (which will involve downloading vs uploading the avatar).