Connecting to an external source of avatars?

I already know about gravatars and external system avatars, but would it be possible to assign a user’s avatar to some other external image? In my case, the user should not be able to change their avatar, instead their avatar is determined by some other system that specifies what it should be.

In part of this “system”, I can call a PUT request to update a user’s avatar, for example:

$.ajax({
    url: 'https://example.com/site/selectable-avatars.json',
    type: 'GET',
    success: function(data) {
        const payload = {
            url: data[1] // Hard coded for now. Will assign later based on some data
        }
        $.ajax({
            url: 'https://example.com/u/' + username + '/preferences/avatar/select',
            type: 'PUT',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'Api-Key': 'my-api-key',
                'Api-Username': 'my-api-username'
             },
             data: JSON.stringify(payload),
             success: function(data, textStatus) {
                 console.log(data, textStatus);
             }
        })
     }
  )}

and this works perfectly, assigning the avatar image to the image passed in, which in this case is hard coded as data[1]. The data is an array of images, set in the discourse settings as “selectable avatars”.

The problem is the image url is actually constructed as https://example.com/${url} rather than just url

I guess what it comes down to is, would it be possible to set the avatar file to an external image (from another domain) rather than an internal image and/or is there a better way to do what I’m trying to do?

Thank you for your time.

You can get this in a supported way using Official Single-Sign-On for Discourse (sso) and the related settings.

2 Likes