# 连接到外部头像来源？

**URL:** <https://meta.discourse.org/t/connecting-to-an-external-source-of-avatars/158432>\
**Category:** Development\
**Created:** [2020年七月21日 18:58 UTC](https://meta.discourse.org/t/connecting-to-an-external-source-of-avatars/158432 "2020-07-21T18:58:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![charl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/charl/32/140161_2.png) [@charl](https://meta.discourse.org/u/charl)\
**Post date:** [2020年七月21日 18:58 UTC](https://meta.discourse.org/t/connecting-to-an-external-source-of-avatars/158432/1 "2020-07-21T18:58:34Z")

</div>

我已经了解 Gravatar 和外部系统头像，但能否将用户的头像指定为其他外部图片？在我的场景中，用户不应能够更改头像，而是由另一个系统根据特定规则确定头像。

在这个“系统”的一部分中，我可以调用 PUT 请求来更新用户的头像，例如：

```
$.ajax({
    url: 'https://example.com/site/selectable-avatars.json',
    type: 'GET',
    success: function(data) {
        const payload = {
            url: data[1] // 目前硬编码，后续会根据某些数据分配
        }
        $.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);
             }
        })
     }
  })

```

这段代码运行完美，成功将头像设置为传入的图片（目前硬编码为 `data[1]`）。这里的 `data` 是一个图片数组，已在 Discourse 设置中配置为“可选头像”。

问题是，实际的图片 URL 构造方式为 `https://example.com/${url}`，而不是直接使用 `url`。

我想问题的关键在于：是否可以将头像文件设置为外部图片（来自其他域名），而不是内部图片？或者是否有更好的方法来实现我的目标？

感谢您的时间。

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2020年七月21日 19:04 UTC](https://meta.discourse.org/t/connecting-to-an-external-source-of-avatars/158432/2 "2020-07-21T19:04:14Z")

</div>

> [@charl](#):
>
> 在我的情况下，用户不应能够更改其头像，而是由其他系统指定其头像内容。

您可以通过 [Discourse 官方单点登录 (SSO)](https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/13045) 及相关设置，以受支持的方式实现此功能。
